How can I convert a "yyyy-MM-dd'T'HH:mm:ssZ'" format in a dataframe to a datetime format that I can further format to an index
2021-01-02T05:22:58.000Z
is one of the dates in the dataframe
i've tried this line of code:
df['created_at_tweet']= pd.to_datetime(df['created_at_tweet'], format=("yyyy-MM-dd'T'HH :mm:ss.SSS'Z'"))
but i get the error
ValueError: time data '2021-01-02T01:43:32.000Z' does not match format 'yyyy-MM-dd'T'HH :mm:ss.SSS'Z'' (match)
any ideas?
CodePudding user response:
This works
df = pd.DataFrame({'created_at_tweet' : ['2021-01-02T01:43:32.000Z'], 'tweet' : ['Hello Twitter!']})
df['created_at_tweet']= pd.to_datetime(df['created_at_tweet'], format=('%Y-%m-%dT%H:%M:%S.%f'))
yields
df