Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
communitycreator

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

Onyejiaku Theophilus Chidalu

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)
Implementing the day_name() function

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.

RELATED TAGS

pandas
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring