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
Comment From: sinhrks
Thx for the report. Because keys
is simply handled as sequence, we need name preserving logic around here.
- https://github.com/pydata/pandas/blob/master/pandas/tools/merge.py#L1351
PR is welcome.
Comment From: jreback
dupe of https://github.com/pydata/pandas/issues/13475 (though this is about MultiIndex, its the same thing)