首页 > 解决方案 > 重新读取excel而不格式化日期

问题描述

熊猫 1.1.0 Python 3.8

当我尝试使用read_excel 方法读取 excel 文件时

文件加载正常,但 excel 在某些列中有日期格式,pandas 会自动更改格式

我想避免这种行为

标签: pythonpython-3.xexcelpandas

解决方案


您可以在 read_excel 函数中设置 dtypes 参数,例如

df=pd.read_excel('excel.xlsx', dtypes={'datecolumnname1':str, 'datecolumnnam2':str,...})

推荐阅读