Pandas Multiple ISO Time Columns To_datetime
I have multiple columns with ISO data strings like 'CreateDate': '2020-04-30T06:12:29.424Z', 'ApprovedDate': '2020-04-30T06:21:30.504Z' When I use column by column with df['Create
Solution 1:
Since you have nice ISO format strings, you should not be required to call to_datetime
with any keywords. Therefore, a simple apply
should be an option:
import pandas as pd
df = pd.DataFrame({"CreateDate": ["2020-04-30T06:12:29.424Z"],
"ApprovedDate": ["2020-04-30T06:21:30.504Z"]})
df[['CreateDate', 'ApprovedDate']] = df[['CreateDate', 'ApprovedDate']].apply(pd.to_datetime)
# df
# CreateDate ApprovedDate
# 0 2020-04-30 06:12:29.424000+00:00 2020-04-30 06:21:30.504000+00:00
Post a Comment for "Pandas Multiple ISO Time Columns To_datetime"