w3resource

Pandas: Create a time series object with a time zone


18. Time Series with Time Zone

Write a Pandas program to create a time series object with a time zone.

Sample Solution:

Python Code :

import pandas as pd
print("Timezone: Europe/Berlin:")
print("Using pytz:")
date_pytz = pd.Timestamp('2019-01-01', tz = 'Europe/Berlin')
print(date_pytz.tz)  
print("Using dateutil:")
date_util = pd.Timestamp('2019-01-01', tz = 'dateutil/Europe/Berlin')
print(date_util.tz)
print("\nUS/Pacific:")
print("Using pytz:")
date_pytz = pd.Timestamp('2019-01-01', tz = 'US/Pacific')
print(date_pytz.tz)  
print("Using dateutil:")
date_util = pd.Timestamp('2019-01-01', tz = 'dateutil/US/Pacific')
print(date_util.tz)

Sample Output:

Timezone: Europe/Berlin:
Using pytz:
Europe/Berlin
Using dateutil:
tzfile('/usr/share/zoneinfo/Europe/Berlin')

US/Pacific:
Using pytz:
US/Pacific
Using dateutil:
tzfile('/usr/share/zoneinfo/US/Pacific')

For more Practice: Solve these Related Problems:

  • Write a Pandas program to generate a timezone-aware time-series and then convert it to a different specified timezone.
  • Write a Pandas program to create a datetime index localized to a given timezone and verify the timezone attribute.
  • Write a Pandas program to generate a time-series with time zone information and then perform arithmetic between dates in different time zones.
  • Write a Pandas program to create a time-series with a specified timezone and then convert all timestamps to UTC.

Go to:


Previous: Write a Pandas program to convert unix/epoch time to a regular time stamp in UTC. Also convert the said timestamp in to a given time zone.
Next:Write a Pandas program to remove the time zone information from a Time series data.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.