Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
MultiIndex DataFrame to_csv() terminates python process #26303
Code Sample, a copy-pastable example if possible
import traceback import pandas as pd # index is actually a MultiIndex index = pd.Index([(1,), (2,), (3,)]) data = pd.DataFrame([[1, 2, 3]], columns=index) data = data.reindex(columns=[(1,), (3,)]) try: # This call fails with a TypeError. data.to_csv('crash.csv') except TypeError as err: traceback.print_exc() # This print seems to be essential to trigger an immediate crash of the process # in the following .to_csv call. The crash happens also if the preceding # try/except block is removed. print(data) data.to_csv('crash.csv')
The python-code above shows two, maybe three errors.
The Windows event log shows an error happened in lib\site-packages\pandas_libs\writers.cp36-win_amd64.pyd.
Because the DataFrame is printable on the console, I would expect a successful call of to_csv().