I have a data frame which has the time_zone and the date in different columns. I want to get the local time corresponding to the time_zone.
I have the data frame as below:
df = pd.DataFrame({'CREATED_DT':['2017-01-01 20:24:21','2017-01-01 21:10:54','2017-01-02 11:48:12','2017-01-02 19:30:53','2017-01-02 21:06:55'],
'Time_Zone':['EST','EST','CET','EST','CST']})
df['CREATED_DT'] = pd.to_datetime(df['CREATED_DT']).dt.tz_localize('UTC')
I have converted the created date to UTC and the time_zone is in a different column. I want to get the local time corresponding to the timezone. So the code for it is :
df['Local_Time'] = df.apply(lambda x: x['CREATED_DT'].tz_convert(x['timezone']), axis = 1)
Which works fine in case the time_zone is EST,CET but gives an error for CST which says:
UnknownTimeZoneError: ('CST', u'occurred at index 4')
I am not sure if there is a way to handle this other than hard coding ... please suggest if there is any other library or function that could be used?