pandas.to_json output date format in specific form
12,903
The easiest fix is to first convert your datetime
series to an object
dtype series of strings:
df['Date'] = df['Date'].dt.strftime('%Y-%m-%d')
I advise you only do this as a final step prior to json conversion, as you lose benefits of vectorised computations and likely will see less efficient memory usage.
Author by
Chan Austin
Updated on July 20, 2022Comments
-
Chan Austin almost 2 years
The original form of date in dataframe is:
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
After converted to json,
df.to_json(orient='index',date_format='iso')
it looks like this:"2018-09-17T00:00:00Z":{"
any way to fix this?