python - 带有日期时间索引的熊猫 to_json 和 read_json
问题描述
我有一个pd.DataFrame
带有索引类型的Timestamp
。
当我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
解决方案
pandas.to_datetime
与参数一起使用unit='ms'
import pandas as pd
print(pd.to_datetime(1629417600000, unit='ms')) # 2021-08-20 00:00:00
推荐阅读
- makefile - 了解使用 Make 执行的 shell 命令/配方
- reactjs - 如何连接 Algolia 和 @material-ui
- linux - 如何将 HugePages 与 pmem 分配一起使用?
- python - 为什么,在父类上调用带有self的函数时,子类实际上是在Python中运行的
- c# - 有什么方法可以在 IdentityServer4 中即时更改 client_id 和 client_secret
- ios - Xcode 10 - 以编程方式添加按钮时,滚动视图不允许滚动
- c - 如何在 C 中跟踪特定的函数/文件?
- android - 如何实现对整个RecyclerView的平移和缩放
- angular - Angular cdk-virtual-scroll-viewport 鼠标滚动不能在水平方向上仅使用鼠标滚轮
- java - 是否有将openjdk hs_err_pid 崩溃文件上传给开发人员的流程?