﻿ Pandas: Extract the day name from a specified date - w3resource

# Pandas: Extract the day name from a specified date

## Pandas Time Series: Exercise-25 with Solution

Write a Pandas program to extract the day name from a specified date. Add 2 days and 1 business day with the specified date.

Sample Solution:

Python Code :

``````import pandas as pd
newday = pd.Timestamp('2020-02-07')
print("First date:")
print(newday)
print("\nThe day name of the said date:")
print(newday.day_name())
print("\nAdd 2 days with the said date:")
newday1 = newday + pd.Timedelta('2 day')
print(newday1.day_name())
nbday = newday + pd.offsets.BDay()
print(nbday.day_name())
``````

Sample Output:

```First date:
2020-02-07 00:00:00

The day name of the said date:
Friday

Add 2 days with the said date:
Sunday

Monday
```

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