Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: unexpected assign by a single-element list #19474

ghost opened this Issue Jan 31, 2018 · 1 comment


None yet
1 participant
Copy link

ghost commented Jan 31, 2018

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame([[1,2,3], [4,5,6]],columns=["A", "B", "C"])
df.loc[0, ["C"]] = ["Z"]
   A  B    C
0  1  2  [Z]
1  4  5    6

Problem description

This issue is derived from

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

   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"]
   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"]
   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
   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]
   A  B  C
0  1  2  9
1  4  5  6

Output of pd.show_versions()


commit: None
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

@jreback jreback added this to the Next Major Release milestone Feb 8, 2018


This comment has been minimized.

Copy link

jreback commented Feb 8, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.