【问题标题】:Rread excel without formatting date读取excel而不格式化日期
【发布时间】:2020-11-30 16:31:36
【问题描述】:

熊猫 1.1.0 Python 3.8

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

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

我想避免这种行为

【问题讨论】:

  • 看看这个answer
  • 你能不能 print(df.dtypes) 在幕后,格式无关紧要,日期时间只是一个数字 - 或自纪元以来的滴答数。您可以将格式更改回默认值。

标签: python python-3.x excel pandas


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-07
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多