Description
Code Sample, a copy-pastable example if possible
import pandas as pd
pd.show_versions()
# Create Multi-Index
df = pd.DataFrame({'col1':[1,2,3], 'col2':[11,12,13]})
df = pd.concat([df], keys=['multi'], names=['level1'], axis=1)
for i in range(100):
df[i, 'colA'] = 10
a = pd.DataFrame({'col1':[1,2,3], 'col2':[11,12,13]})
a = pd.concat([a], keys=['multi'], names=['level1'], axis=1)
df = df.append(a, ignore_index=True)
print(df['multi'])
Problem description
Raises an exception "KeyError: 'multi' ", although this should perfectly work, as the key "Multi" exists, e.g when printing df.columns.
The most strange thing is:
- The step in which this exception is raised depends on the Name of the key "Multi".. Sometimes 2nd loop, sometimes 6th,...
- During the first loop it works perfectly and prints the df
However it has to do something with using "integer" and "string" column-names for level1 --- if i use an integer, e.g. -1 instead of "Multi", this seems to work.
Expected Output
It prints 100 times the dataframe
Output of pd.show_versions()
pandas : 0.25.3
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 39.0.1
Cython : None
pytest : 5.2.2
hypothesis : None
sphinx : 2.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None