+

Python | Pandas DatetimeIndex.month_name ()

DatetimeIndex.month_name() Pandas DatetimeIndex.month_name() returns the month names of the DateTimeIndex with the specified locale ... The default is None, in which case names are returned in English.

Syntax: DatetimeIndex.month_name (locale = None)

Parameters:
locale: locale determining the language in which to return the month name

Return: Index of month names

Example # 1: Use DatetimeIndex.month_name () to return the month name of each record in a DatetimeIndex object. Return French month names

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here "Q" represents the quarterly frequency

didx = pd.DatetimeIndex (start = ` 2018-11-15 09: 45: 10` , freq = ` Q` , periods = 5 )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to return the month names in French.

# return the month names in French

didx.month_name (locale = `French` )

Output:

As we can see from the output, the function returned an Index object containing month names in French.

Example # 2: Use DatetimeIndex.month_name () to return the name the month of each entry in the DatetimeIndex object. Return German month names

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here "M" represents the monthly frequency

didx = pd.DatetimeIndex (start = ` 2015-03-02` , freq = `M ` , periods = 5 )

  
# Print DatetimeIndex

print (didx)

Output:

Now we want to return the month names in German.

# return the month names in German

didx.month_name (locale = `German` )

Output:

As we can see from the output, the function returned an Index object containing the names of the month in German.

Get Solution for free from DataCamp guru