【问题标题】:pandas to_json and read_json with datetime index带有日期时间索引的熊猫 to_json 和 read_json
【发布时间】:2021-10-27 17:10:09
【问题描述】:

我有一个索引类型为Timestamppd.DataFrame

当我 to_json 数据帧时,索引将转换为 '1629849600000' 之类的东西。

我不能pd.to_datetime这个或datetime.datetime.fromtimestamp它。

如果我 pd.DataFrame 的 json 格式正确:

如果我pd.to_datetime这个,它会失败

OverflowError: Python int too large to convert to C long

【问题讨论】:

  • 你有原始数据的样本吗?
  • @azro 请作为答案提交。

标签: python pandas


【解决方案1】:

使用pandas.to_datetime 和参数unit='ms'

import pandas as pd

print(pd.to_datetime(1629417600000, unit='ms'))  # 2021-08-20 00:00:00

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2019-06-27
    • 1970-01-01
    • 2012-12-30
    • 2023-01-12
    • 2019-02-19
    • 1970-01-01
    相关资源
    最近更新 更多