I have a df
with a columns that contains, in two different string format, several timestamps.
These are the two formats:
fmt = "%a %b %d %H:%M:%S %Z%z %Y"
fmt_2 = "%a %b %d %H:%M:%S %Z %Y"
Thanks to this community, if I had just one type of string format I would be able to convert to datetime
using
.apply(lambda x: datetime.strptime(x, fmt)
stamp = "Fri Oct 11 15:09:30 GMT+01:00 2019"
stamp_2 = 'Sun Oct 27 08:05:47 GMT 2019'
stamp_3 = 'Sat Oct 26 08:05:47 GMT 2019'
stamp_4 = "Sat Oct 12 15:09:30 GMT+01:00 2019"
#How I would convert the two format
#from string to datetime
#
fmt = "%a %b %d %H:%M:%S %Z%z %Y"
print(datetime.strptime(stamp, fmt))
fmt_2 = "%a %b %d %H:%M:%S %Z %Y"
print(datetime.strptime(stamp_2, fmt_2))
#building an example dataframe
question_dict = {"time":[stamp, stamp_2,
stamp_3,stamp_4],
"record":[1,2,3,4]}
question_df = pd.DataFrame(question_dict)
print(question_df.info())
How can I convert the elements in my column from string to datetime?
I tried to search but please let me know if my question is a duplicate.