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
+0000in the format code? this will get you into trouble in case the UTC offset changes... In general, I think you don't need a format code here at all; pandas will auto-detect ISO8601 just fine.+-xxxx. Do you want the output to have that as well?