﻿ Pandas: Date from a given year, month, day and date from a given string formats - w3resource

# Pandas: Date from a given year, month, day and date from a given string formats

## Pandas Time Series: Exercise-3 with Solution

Write a Pandas program to create a date from a given year, month, day and another date from a given string formats.

Sample Solution:

Python Code :

``````from datetime import datetime
date1 = datetime(year=2020, month=12, day=25)
print("Date from a given year, month, day:")
print(date1)
from dateutil import parser
date2 = parser.parse("1st of January, 2021")
print("\nDate from a given string formats:")
print(date2)
``````

Sample Output:

```Date from a given year, month, day:
2020-12-25 00:00:00

Date from a given string formats:
2021-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}
```