Skip to content
Advertisement

Converting Unix timestamp to timestamp including the local time of a certain timezone

I have following code:

df['time'] = (pd.to_datetime(df['unix_time'], unit='s'))
df['time'] = (pd.to_datetime(df['unix_time'], unit='s',tz='Europe/Vienna'))

First line runs but when I try to set the new timestamp as a local time for that timezone I get an error as – **to_datetime() got an unexpected keyword argument ‘tz’**

Thanks

Advertisement

Answer

pd.to_datetime(df['unix_time'], unit='s').tz_localize('Europe/Vienna')

or alternatively

pd.to_datetime(df['unix_time'], unit='s',utc=True).tz_convert('Europe/Vienna')
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement