Skip to content

Dataframe loses level name after concat, only if columns types are str #27230

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

Closed
pepicello opened this issue Jul 4, 2019 · 2 comments
Closed
Labels
Duplicate Report Duplicate issue or pull request

Comments

@pepicello
Copy link
Contributor

Code Sample

a = pd.DataFrame([1], index=[1], columns=['1'])
a.columns.names = ['n']
b = pd.DataFrame([1, 1], index=['1', '2'], columns=[1]).T
b.columns.names = ['n']
df1 = pd.concat([a, b])

a = pd.DataFrame([1], index=[1], columns=[1])
a.columns.names = ['n']
b = pd.DataFrame([1, 1], index=[1, 2], columns=[1]).T
b.columns.names = ['n']
df2 = pd.concat([a, b])

Problem description

When concatenating two dataframes with the same column level name ('n' in the case above), it is expected to find the same level name after the concatenation, i.e. on df1. This is not the case. If the columns are not str, as in df2, the behaviour is as expected. If this is not the expected behaviour, the two results should at least agree.

Expected Output

df1.columns.name == df2.columns.name

Output of pd.show_versions()

commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.17.0rc1
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd
Copy link
Member

WillAyd commented Jul 4, 2019

I think this is a duplicate of #21629 - can you check?

@pepicello
Copy link
Contributor Author

Yes, looks like it is. The only addition here is that it does not happen with non-str, but this can be closed as solving that issue should also solve this. Thanks!

@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants