﻿ Pandas: Create a time series object with a time zone - w3resource

# Pandas: Create a time series object with a time zone

## Pandas Time Series: Exercise-18 with Solution

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

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