You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At first I thought this happened because the method is not idiomatic. But I noticed a method with numpy.array is showed in here (section:Setting) df.loc[:,'D'] = np.array([5] * len(df))
So I reported this just in case. Sorry but I cannot judge whether my method is completely non-idiomatic
or whether latest reported bugs contains mine.
Expected Output
df
A B C
0 1 2 Z
1 4 5 6
Some trials and errors
#more elements : as I expected
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
df.loc[0, ["A", "B"]] = ["X", "Y"]
df
A B C
0 X Y 3
1 4 5 6
#axis=0 : as I expected
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
df.loc[[0], "C"] = ["Z"]
df
A B C
0 1 2 Z
1 4 5 6
#using numpy.array : NOT as I expected
import numpy as np
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
s = np.array(["Z"])
df.loc[0, ["C"]] = s
df
A B C
0 1 2 [Z]
1 4 5 6
#assign instead a list containing int : as I expected
df = pd.DataFrame([[1,2,3], [4,5,6]],columns=["A", "B", "C"])
df.loc[0, ["C"]] = [9]
df
A B C
0 1 2 9
1 4 5 6
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
yeah I think this should infer this list-like asd you are assigning to a Series (because of the list for the columns). a pull-request or deeper investigation would be great.
Code Sample, a copy-pastable example if possible
Problem description
This issue is derived from https://stackoverflow.com/questions/48195993/unexpectedly-assign-in-pandas-by-df-loc-and-single-element-list
At first I thought this happened because the method is not idiomatic. But I noticed a method with numpy.array is showed in here (section:Setting)
df.loc[:,'D'] = np.array([5] * len(df))
So I reported this just in case. Sorry but I cannot judge whether my method is completely non-idiomatic
or whether latest reported bugs contains mine.
Expected Output
Some trials and errors
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.2.5
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: