简体   繁体   English

使用.to_json将数据帧转换为JSON会弄乱日期时间数据

[英]using .to_json to convert a data-frame to JSON messes up datetime data

I have a 4 column dataframe with just one row of data. 我有一个4列数据框,其中只有一行数据。 I convert that row of data to JSON for the purpose of making a POST request to an API with it. 我将该数据行转换为JSON,目的是使用它向API发出POST请求。 I do this by using: 我通过使用以下方法做到这一点:

data = local_materials.loc[local_materials['id'] == apicounter]

In the dataframe, one of the columns (date) has the following data: 在数据框中,列(日期)之一具有以下数据:

1971-12-17 00:00:00

When I run data = data.to_json(orient='records') it transforms the data data into "date":61776000000 当我运行data = data.to_json(orient='records')它将数据数据转换为"date":61776000000

Does anyone have any advice for maintaining a datetime parse C# format? 有人对维持日期时间解析C#格式有任何建议吗?

use date_format='iso' as in: 使用date_format='iso'如下:

data.to_json(orient='records', date_format='iso')

For reference: 以供参考:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_json.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_json.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM