Reputation: 59
I have a dataframe with a column datetime that looks like this 2020-05-03T14:51:31.23625 (I assume %Y-%m-%dT%H:%M:%S) I would like to change it to dd/mm/yyyy hh:mm:ss format. I found this post and I tried something similar (code below) but it works ony for the first row of the dataframe. Could someone help me to find the mistake? Thanks!
df['time']=pd.DataFrame({'time':pd.to_datetime(df['time'])})
df['new'] = df['time'].dt.strftime("%d/%m/%Y %H:%M:%S")
[![enter image description here][2]][2]
Upvotes: 0
Views: 60
Reputation: 24322
Try via split()
and to_datetime()
method:
df['datetime']=pd.to_datetime(df['datetime'].str.split('.').str[0],errors='coerce')
Upvotes: 1