Pandas: Extract the day name from a specified date
25. Extract Day Name and Adjust Dates
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
For more Practice: Solve these Related Problems:
- Write a Pandas program to extract the day name from a given date and then add 2 days and subtract 1 business day to compute new dates.
- Write a Pandas program to derive the weekday name from a Timestamp and then adjust the date by a combination of calendar and business day offsets.
- Write a Pandas program to create a function that extracts the day name from a date and then adds a specified number of business days.
- Write a Pandas program to extract the day name from a datetime object, add two days, and then compare the resulting weekday with the original.
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.