Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
communitycreator

How to obtain the month name of a Timestamp object in Pandas

Onyejiaku Theophilus Chidalu

Overview

The month_name()function of Pandas.Timestamp—an equivalent of Python's datetime object—is used to return the name of the month of the Timestamp object.

Syntax

Timestamp.month_name()
Syntax of the month_name() function

Parameter value

The month_name() function takes a single optional parameter value, locale, which represents the language in which the month name is returned.

Return value

The month_name() function returns a str, which represents the month name.

Example

# A code to illustrate the month_name() function in Pandas
# importing the pandas library
import pandas as pd

# creating a Timestamp object
a = pd.Timestamp(2022, 4, 29)

# obtaining the month name of the Timestamp object
print(a.month_name())
Implementing the month_name() function

Explanation

  • Line 3: We import the Pandas library.
  • Line 6: We use the Pandas.Timestamp() function to create a Timestamp object, a.
  • Line 9: We use the month_name() function to obtain and print the month name of the date time object.

RELATED TAGS

pandas
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring