﻿ Pandas: Time zone information from a Time series data - w3resource

Pandas: Time zone information from a Time series data

Pandas Time Series: Exercise-19 with Solution

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
```

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 Python skills with w3resource's quiz

﻿

Python: Tips of the Day

Merging two dicts in Python 3.5+ with a single expression

Example:

```# How to merge two dictionaries
# in Python 3.5+

x = {'p': 1, 'q': 3}
y = {'q': 5, 'r': 8}

z = {**x, **y}

z
{'r': 4, 'p': 1, 'q': 3}

z = dict(x, **y)
print(z)
```

Output:

```{'p': 1, 'q': 5, 'r': 8}
```