Skip to content

Can it impossible to fill names parameter of concat() when keys is specified with Index/MultiIndex object? #13742

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
s-wakaba opened this issue Jul 21, 2016 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@s-wakaba
Copy link

Thanks for all developers,

I think it's useful and natural behaviour
when keys parameter of concat() function is specified with Index or MultiIndex object, its name or names attribute is not taken over to the result DataFrame object.

>>> import pandas as pd
>>> a1 = pd.DataFrame([[110, 111], [120, 121]])
>>> a1.index.name = 'index_X'
>>> a2 = pd.DataFrame([[210, 211], [220, 221]])
>>> a2.index.name = 'index_X'
>>> b = pd.concat([a1, a2], keys=['a1', 'a2'], names=['index_Y'])
>>> b
                   0    1
index_Y index_X          
a1      0        110  111
        1        120  121
a2      0        210  211
        1        220  221
>>> b_index = pd.Index(['a1', 'a2'], name='index_Y')
>>> b = pd.concat([a1, a2], keys=b_index)
>>> b # name of b_index is not taken over!
              0    1
   index_X          
a1 0        110  111
   1        120  121
a2 0        210  211
   1        220  221

In such case, I think it's useful and natural behavior that the name of 1st level of the result indices is automatically set as "index_Y".
Are there any probrems or difficulties if this change will be applied?

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-31-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
@sinhrks
Copy link
Member

sinhrks commented Jul 21, 2016

Thx for the report. Because keys is simply handled as sequence, we need name preserving logic around here.

PR is welcome.

@sinhrks sinhrks added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jul 21, 2016
@sinhrks sinhrks added this to the 0.20.0 milestone Jul 21, 2016
@jreback
Copy link
Contributor

jreback commented Jul 21, 2016

dupe of #13475 (though this is about MultiIndex, its the same thing)

@jreback jreback closed this as completed Jul 21, 2016
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Jul 21, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: No action, 0.20.0 Jul 21, 2016
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 Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

4 participants