w3resource

Pandas: Time zone information from a Time series data


19. Remove Time Zone Information

Write a Pandas program to remove the time zone information from a Time series data.

Sample Solution:

Python Code :

import pandas as pd
date1 = pd.Timestamp('2019-01-01', tz='Europe/Berlin')
date2 = pd.Timestamp('2019-01-01', tz='US/Pacific')
date3 = pd.Timestamp('2019-01-01', tz='US/Eastern')
print("Time series data with time zone:")
print(date1)
print(date2)
print(date3)
print("\nTime series data without time zone:")
print(date1.tz_localize(None))
print(date2.tz_localize(None))
print(date3.tz_localize(None))

Sample Output:

Time series data with time zone:
2019-01-01 00:00:00+01:00
2019-01-01 00:00:00-08:00
2019-01-01 00:00:00-05:00

Time series data without time zone:
2019-01-01 00:00:00
2019-01-01 00:00:00
2019-01-01 00:00:00

For more Practice: Solve these Related Problems:

  • Write a Pandas program to remove the timezone information from a timezone-aware time-series and convert it to naive datetime objects.
  • Write a Pandas program to strip the timezone from a datetime index and then confirm the change in data type.
  • Write a Pandas program to create a timezone-aware series and then drop its timezone while ensuring the datetime values remain unchanged.
  • Write a Pandas program to convert a timezone-aware DataFrame column to naive datetimes and perform arithmetic operations.

Python Code Editor:

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

Previous: Write a Pandas program to create a time series object with a time zone.
Next: Write a Pandas program to subtract two timestamps of same time zone or different time zone.

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.