10000 combine_first: 'DataFrame' object has no attribute 'dtype' with duplicate columns · Issue #29135 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

combine_first: 'DataFrame' object has no attribute 'dtype' with duplicate columns #29135

@stippingerm

Description

@stippingerm

Code Sample, a copy-pastable example if possible

df1 = pd.DataFrame([[1,np.nan],[3,4]], columns=['P','Q'], index=['A', 'B'])
df2 = pd.DataFrame([[5,6,7],[8,9,np.nan]], columns=['P','Q','Q'], index=['A', 'B'])
df1.combine_first(df2)
# or alternatively: df2.combine_first(df1)

Problem description

The above call results in AttributeError: 'DataFrame' object has no attribute 'dtype' which is difficult to interpret. Under the hood the set logic tries to maintain dtype but the duplicate column label results in finding a DataFrame instead of a Series. The former has no dtype but dtypes.

Expected Output

Performing some calculation, e.g.,

   P    Q    Q
A  1  6.0  7.0
B  3  4.0  4.0

Output of pd.show_versions()

Details

INSTALLED VERSIONS

commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.24.2
pytest: 5.0.1
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.29.12
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.6.1
sphinx: 2.1.2
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.2
numexpr: 2.6.9
feather: None
matplotlib: 3.1.0
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.3.4
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0