-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Replacing a column with iloc replaces another column with same name #22036
Comments
Strange indeed - investigation and PRs welcome! |
Seems problem is with pandas/pandas/core/indexing.py Lines 526 to 548 in a6c7387
as I understand item is a column name, so on line 527 we're selecting both columns as they have the same name
|
This was referenced Feb 29, 2020
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample, a copy-pastable example if possible
Problem description
The issue seems to be that if there is a DataFrame with duplicate column names and mixed dtypes, if I try to replace one column with another value, using
iloc
, another column with same name is replaced as well.Expected Output
The final print should be:
And not:
It is interesting that if I change concat line to (see renaming of column
b
toc
):Then the output is correctly:
Also, if
a.iloc[:, 0] = [int(v) for v in a.iloc[:, 0]]
is commented out, it works also correctly.Moreover, the following also work correctly (see the change of
0
column index into[0]
column index, and similar for2
(this latter change is not really necessary to make it work)):Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-46-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.3
pytest: None
pip: 18.0
setuptools: 40.0.0
Cython: None
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
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: