I have a dataframe that has two columns named created_at
and updated_at
which are date strings with format %Y-%m-%dT%H:%M:%S+0000
. I need them to be converted to '%Y-%m-%d %H:%M:%S'
. I have tried the following things but none works:
data[['created_at', 'updated_at']] = pd.to_datetime(
data[['created_at', 'updated_at']], format='%Y-%m-%dT%H:%M:%S+0000').dt.strftime('%Y-%m-%d %H:%M:%S')
data[['created_at', 'updated_at']] = data[['created_at', 'updated_at']].apply(
lambda x: datetime.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S+0000').strftime('%Y-%m-%d %H:%M:%S'))
data[['created_at', 'updated_at']] = pd.to_datetime(
data[['created_at', 'updated_at']], infer_datetime_format=True, utc=True)
How could I solve it? Thanks
Use:
f = lambda x: pd.to_datetime(x, utc=True).dt.strftime('%Y-%m-%d %H:%M:%S')
data[['created_at', 'updated_at']] = data[['created_at', 'updated_at']].apply(f)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments