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())
print("\nNext business day:")
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

Next business day:
Monday

Python Code Editor:

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

Previous: Write a Pandas program to generate time series combining day and intraday offsets intervals.
Next: Write a Pandas program to convert integer or float epoch times to Timestamp and DatetimeIndex.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/pandas/time-series/pandas-time-series-exercise-25.php