Description
Code Sample, a copy-pastable example if possible
import pandas as pd
df = pd.DataFrame(
data=[1., 2., 3.],
columns=pd.MultiIndex.from_tuples(
[('A', 'X')],
names=['Top', 'Bottom'],
)
)
df2 = df.astype({('A', 'X'): 'int'})
print(df.columns.names)
print(df2.columns.names)
Problem description
df2
should have the same column.names
as df
. What actually happens is that the column.names
become [None, None]
.
If instead the definition of df2
becomes:
df2 = df.astype('int')
Then the expected behavior is observed.
Expected Output
['Top', 'Bottom']
Output of pd.show_versions()
pandas: 0.22.0
pytest: 4.6.2
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.28.5
numpy: 1.14.5
scipy: 1.0.1
pyarrow: None
xarray: 0.11.3
IPython: 5.8.0
sphinx: 1.8.5
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 2.2.3
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml: 4.2.4
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None