Mike
Mike

Reputation: 99

Use pytz to convert pandas dataframe column with timestamps from UTC to local timezone?

I have a table with time-stamped data, like this:

enter image description here

How do I convert the entire TimeStamp column from UTC to local time with the pytz module? Input is an IANA formatted timezone, like eg. "Europe/London". The table is stored in a pandas dataframe.

Upvotes: 0

Views: 1733

Answers (1)

user96564
user96564

Reputation: 1607

Do you really need the pytz module ? You can use tz info within the pandas.

for eg. something like this can be done:

df['timestamp'] = df['timestamp'].dt.tz_localize('UTC').dt.tz_convert('Europe/London')

You may want to check more detail here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.tz_convert.html

Upvotes: 0

Related Questions