-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import numpy as np
#set up test df
df = pd.DataFrame({'str_addr_1':[np.nan,'str1b'],
'city_1':[np.nan,'city1b'],
'state_1':[np.nan,'state1b'],
'zip_code_1':[np.nan,'zip1b'],
'str_addr_2':['str2a','str2b'],
'city_2':['city2a','city2b'],
'state_2':['state2a','state2b'],
'zip_code_2':['zip2a','zip2b']})
print(f'df:\n {df}')
mask = (df['str_addr_1'].isnull()) & (df['state_2'].notnull())
df.loc[mask, ['str_addr_1','city_1','state_1','zip_code_1']] = df.loc[mask, ['str_addr_2','city_2','state_2','zip_code_2']]
print(f'df after direct assignment with out values: \n {df}')
mask = (df['str_addr_1'].isnull()) & (df['state_2'].notnull())
df.loc[mask, ['str_addr_1','city_1','state_1','zip_code_1']] = df.loc[mask, ['str_addr_2','city_2','state_2','zip_code_2']].values
print(f'df after direct assignment with values: \n {df}')Issue Description
Direct assignment without using .values should work with same index alignment, but doesn't seem to work here.
Expected Behavior
direct assignment without .values on the right side would populate values on the left side columns.
Installed Versions
INSTALLED VERSIONS
commit : a671b5a
python : 3.11.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 2.1.4
numpy : 1.26.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.2
pip : 23.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.18.1
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : 0.58.1
numexpr : None
odfpy : None
openpyxl : 3.2.0b1
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : 2.0.23
tables : None
tabulate : None
xarray : 2023.12.0
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None