BUG: read_csv does not comply with the to_csv format (no support of df.columns.names)

This issue has been created since 2022-11-23.

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
mi1 = pd.MultiIndex.from_arrays([[1, 2]], names=['s'])
mi3 = pd.MultiIndex.from_arrays([[1, 2], [3, 4], [5, 6]], names=['x', 'y', 'z'])
df = pd.DataFrame(index=mi3,columns=mi1)
df.to_csv("data.csv")
df2=pd.read_csv("data.csv", index_col=[0,1,2], header=[0])
print(df)
print(df2)

Issue Description

read_csv does not support df.columns.names
df != df2

Expected Behavior

df==df2

Installed Versions

python3\Lib\site-packages\_distutils_hack\__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : 91111fd
python : 3.11.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-12-07
Star Count 36164
Watcher Count 1118
Fork Count 15472
Issue Count 3683

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Add support for instrumentation version annotations 0 2022-11-04 2022-12-04
Installation When used with Typescript code: should install and work with code that imports the module and starts with a complete `serviceContext` failed 2 2022-11-23 2022-11-26
Frameless window has no rounded corners Windows 11 3 2021-12-23 2022-11-15
Conversions data formats from phyloseq to TSE 2 2022-01-04 2022-11-06
Amazon plugin crashes on Kodi when loading watchlist 1 2021-09-25 2022-10-28
how to attach XM tag 1 2022-05-02 2022-11-03
Fail to start due to instantiation failure 3 2021-09-16 2022-11-06
DD empty after adding weather entity 2 2022-07-15 2022-11-28
Dtype issue in `TorchNormalizer(method="identity")` 0 2022-05-23 2022-11-27
IllegalStateException PixFragment not attached to an activity while rotating quickly 1 2021-07-14 2022-10-02
Add the possibility to pretrain on multiple tasks 3 2021-09-15 2022-11-24
BUG: Dropping index on a table not adding table name to the query 2 2021-09-21 2022-10-09
Tour not scrolling to view the next component 3 2022-05-01 2022-11-27
`wails dev` panics due to application immediately shutting down 8 2022-08-07 2022-11-13
[v2] delay when dragging a window with `data-wails-drag` attribute 6 2022-08-06 2022-12-01
low download speed 7 2021-09-14 2022-01-05
The great suspender v.7.1.6 is not compatible with Chromium v.104.0.5112.81 3 2022-08-06 2022-11-13
ngtcp2 failed make -j$(nproc) check 8 2021-03-24 2022-11-01
[FEATURE] Disable Sign-ups on Self-Hosted 3 2022-10-07 2022-11-11
UIA MenuItemWrapper select() hangs after menu has already been selected, then raises COMError 1 2022-06-20 2022-11-18
`join` command with `--prefix-components-with-info-prop` looses additional schemes in security requirement 0 2021-10-08 2022-08-02
Difference in msgid_plural and msgstr[1] appears as unchanged string 0 2021-08-08 2022-11-22
Unable to find an entry point named 'GetPackageInfo2' and 'GetStagedPackageOrigin' in DLL 'kernel32.dll'. 2 2022-07-26 2022-11-25
Has fable 3/elmish/react been made to work with webpack 5 or vitejs yet? Nagareyama build documentation 10 2021-07-05 2022-12-07
Ignoring merge conflicts caused by grammars.json 3 2022-11-10 2022-12-07
Select 组件使用异步加载方式 在Form中点击重置按钮 重置表单时 Select不会在从服务端加载选项 1 2021-11-05 2022-11-20
Bucket- and Database-forward might be the same 0 2021-12-16 2022-09-22
remote_jdk12 repositories should have a sha256 attribute 0 2019-09-22 2022-11-25
[email protected]: hash check failed 1 2021-08-27 2022-11-22
Add support for php, erb and soy languages 4 2021-06-23 2022-10-20
Blurry vector map between zoom levels 2 2022-05-27 2022-09-20
Bug on Glob evaluating GLOB_BRACE 1 2020-11-21 2022-11-27
Greetings, program! 1 2021-02-23 2021-12-27
validation bot is confused 1 2021-02-23 2021-12-27
validation bot is confused 0 2021-02-23 2021-12-27
Greetings, program! 1 2021-03-09 2021-12-27
Memory leak due to reusing path element 4 2022-05-16 2022-12-03
after deleting the replica of an object, a folder with a size of zero remains 10 2022-04-18 2022-11-30
pouchdb-find createIndex doesn't write partial_filter_selector 1 2022-06-17 2022-11-17
Fragment array merging issue when array content is not in the same order as server's response (5.0.0-beta.0) 1 2022-03-02 2022-11-20
I have three tables: user, role, and user_role. The user_role table is the relationship between user and role. How should I configure Edges? 4 2021-11-09 2022-11-17
cpp: gigasecond does not compile 9 2021-09-03 2022-11-25
"Consistent AST position" crashes pytest: "ValueError: line 22-0 is not a valid range" 6 2022-05-31 2022-11-12
Some package installed by winget are not marked by winget anymore 10 2021-11-14 2022-10-02
Support DeepSpeed checkpoints with DeepSpeed Inference 0 2021-08-02 2022-11-22
Autolinks extension should ignore URIs inside link descriptions 1 2022-09-14 2022-11-28
Pull annotationProcessorOptions from AGP 0 2021-10-12 2022-11-27
crossSbtVersions should be in excludeLintKeys by default 0 2021-06-30 2022-11-27
base files 0 2017-10-28 2021-11-01
Code Runner Extension doesn't clears the terminal 0 2021-08-20 2022-10-24