gpt4 book ai didi

python - pandas.to_json 以特定形式输出日期格式

转载 作者:太空宇宙 更新时间:2023-11-04 04:30:25 27 4
gpt4 key购买 nike

dataframe中日期的原始形式是:

Date                                                                   
2018-09-17 12.83 12.92 12.38 12.65 12.65 1937329.0
2018-09-10 12.92 13.12 12.81 12.83 12.83 1150470.0

转成json后,df.to_json(orient='index',date_format='iso')它看起来像这样:

"2018-09-17T00:00:00Z":{"

有什么办法可以解决这个问题吗?

最佳答案

最简单的解决方法是首先将您的 datetime 系列转换为 object dtype 系列字符串:

df['Date'] = df['Date'].dt.strftime('%Y-%m-%d')

我建议您只将此作为 json 转换之前的最后一步,因为您会失去矢量化计算的优势,并且可能会发现内存使用效率较低。

关于python - pandas.to_json 以特定形式输出日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52730953/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com