How to return the day name of a Timestamp object in pandas

Overview

The day_name() function in pandas returns the day name of a given Timestamp object. This is equivalent to Python's datetime object.

Syntax

Timestamp.day_name()
Syntax for the day_name() function in Pandas

Parameter value

  • locale: This function takes a single optional parameter value, locale. This is the locale that determines the language in which the day name is returned. By default, it takes the English locale.

Return value

  • str: The day_name() function returns a string that indicates the day name.

Example

# A code to illustrate the day_name() function in Pandas
# Importing the pandas library
import pandas as pd
# Creating a Timestamp object
my_date = pd.Timestamp('2022-04-29T7:48:52.192548651')
# Obtaining the day name from the Timestamp object
name = my_date.day_name()
print("The day from the given date is: ", name)

Explanation

  • Line 3: We import the pandas module.
  • Line 6: We create a Timestamp object and name it my_date.
  • Line 9: We obtain the day name of the Timestamp object (my_date) by using the day_name() function. The result is assigned to the variable name variable.
  • Line 11: We print the value of the name variable.

Free Resources