Issue
I'm trying to remove the T
and 000Z
in my data:
2018-03-20T19:48:12.000Z
2018-07-20T14:33:09.000Z
2018-07-20T14:33:55.000Z
I want to get a timestamp that looks like this:
2018-03-20 19:48:12
2018-07-20 14:33:09
2018-07-20 14:33:55
I tried to format the time using this: NOTE: (OPENEDDATETIME) is the column name.
pd.to_datetime(df['OPENEDDATETIME'], format='%m/%d/%Y')
... but I keep getting this error:
ValueError: time data '2018-03-20T19:48:12.000Z' does not match format '%m/%d/%Y' (match)
Solution
You datetime format is %Y-%m-%dT%H:%M:%S.%fZ
Ex:
import pandas as pd
df = pd.DataFrame({"d": ['2018-03-20T19:48:12.000Z', '2018-07-20T14:33:09.000Z', '2018-07-20T14:33:55.000Z']})
df["d"] = pd.to_datetime(df["d"], format="%Y-%m-%dT%H:%M:%S.%fZ")
print(df)
Output:
d
0 2018-03-20 19:48:12
1 2018-07-20 14:33:09
2 2018-07-20 14:33:55
Answered By - Rakesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.