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

时间:2019-02-01 01:25:12

标签: python json pandas dataframe

我有一个4列数据框,其中只有一行数据。我将该数据行转换为JSON,目的是使用它向API发出POST请求。我使用以下方法做到这一点:

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

在数据框中,列(日期)之一具有以下数据:

1971-12-17 00:00:00

当我运行data = data.to_json(orient='records')时,它将数据数据转换为"date":61776000000

有人对维护日期时间解析C#格式有任何建议吗?

1 个答案:

答案 0 :(得分:2)

使用date_format='iso'如:

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

供参考:

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