Reputation: 632
This is two lines of inputdataframe:
ts country os product_id total_users total_purchases
0 0000-00-00 Brazil iOS 1 0
1 0000-00-00 Germany 1 0
I have tried following commands in order to convert 'ts' which is object to datetime:
df['ts'] = df['ts'].astype('datetime64[ns]')
and this is an error I've got: ValueError: Month out of range in datetime string "0000-00-00"
I know that there is a problem with 0000-00-00, but I don't know how to get ride of it and solve it to work?
Upvotes: 2
Views: 2002
Reputation: 19375
easy peasy
df['ts'] = pd.to_datetime(df['ts'], errors ='coerce')
no need to clean the data. wrong timestamps will get the NaT
(not a timestamp)
Upvotes: 4