Reputation: 923
I am having datecolumn in dataframe like below
df.REFERENCE_DATE
0 2019-11-26
1 2019-11-27
2 2019-11-29
3 2019-11-30
4 2019-11-26
df.dtpes
REFERENCE_DATE datetime64[ns]
df.to_json('date.json', orient='records')
When I am reading the file again this date format get changed into string.
df1=pd.read_json('date.json')
0 1574726400000
1 1574812800000
2 1574985600000
3 1575072000000
df1.dtypes
REFERENCE_DATE object
I want to have date field have same format throughout. How to fix this
Upvotes: 0
Views: 478
Reputation: 323226
Convert it back
pd.to_datetime(df.Date,unit='ms')
Out[62]:
0 2019-11-26
1 2019-11-27
2 2019-11-29
3 2019-11-30
Name: Date, dtype: datetime64[ns]
Upvotes: 1