Reputation: 8247
I have following pandas dataframe with date column as object
ID Date Volume
0 13-02-2018 00:06 85
1 13-02-2018 00:10 70
2 13-02-2018 00:11 100
3 2018-02-13 06:30 123
4 02-13-2018 07:56 100
I want to convert it to following one format
ID Date Volume
0 2018-02-13 00:06 85
1 2018-02-13 00:10 70
2 2018-02-13 00:11 100
3 2018-02-13 06:30 123
4 2018-02-13 07:56 100
I am trying to achieve this by following command
df['Date'] = df.date.apply(lambda x: pd.to_datetime(x).strftime('%Y-%m-%d %H:%M')[0])
But it throws an error. How can I do it in pandas?
Upvotes: 6
Views: 8658
Reputation: 29
Import time
Localtime= time.asctime(time.localtime(time.time()))
Print(localtime)
Check if this we work
Upvotes: -2
Reputation: 5324
try this:
df['Date'] = pd.to_datetime(df.Date)
df['Date'] = df['Date'].dt.strftime('%Y-%m-%d %H:%M')
link: Series.dt.strftime
Upvotes: 5