Ahmed Al Mubarak
Ahmed Al Mubarak

Reputation: 11

How to fix the datetime in python?

I am getting an error message that says time data 2017-01-02 13:42:05.378582 does not match format %y-%m-%d %H:%M:%S.%f

start_time = datetime.datetime.strptime(df['timestamp'].min(),'%y-%m-%d %H:%M:%S.%f')
end_time = datetime.datetime.strptime(df['timestamp'].max(),'%y-%m-%d %H:%M:%S.%f')
data_duration = (end_time - start_time).days

print(f"Number of unique users in experiment: {df['user_id'].nunique()}")

Upvotes: 0

Views: 54

Answers (1)

Yevhen Kuzmovych
Yevhen Kuzmovych

Reputation: 12130

%y is year without century as a zero-padded decimal number (17)

%Y is year with century as a decimal number (2017)

You need: '%Y-%m-%d %H:%M:%S.%f'

Upvotes: 1

Related Questions