Python | Pandas DatetimeIndex.month_name()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas DatetimeIndex.month_name()
function return the month names of the DateTimeIndex with specified locale. The default locale is None in which case the names are returned in English language.
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()
function to return the month name of each entry in the DatetimeIndex object. Return the names of the month in French locale
import pandas as pd
didx = pd.DatetimeIndex(start = '2018-11-15 09:45:10' , freq = 'Q' , periods = 5 )
print (didx)
|
Output :
Now we want to return the names of the month in French locale.
didx.month_name(locale = 'French' )
|
Output :
As we can see in the output, the function has returned an Index object containing the names of the month in French.
Example #2: Use DatetimeIndex.month_name()
function to return the month name of each entry in the DatetimeIndex object. Return the names of the month in German locale
import pandas as pd
didx = pd.DatetimeIndex(start = '2015-03-02' , freq = 'M' , periods = 5 )
print (didx)
|
Output :
Now we want to return the names of the month in German locale.
didx.month_name(locale = 'German' )
|
Output :
As we can see in the output, the function has returned an Index object containing the names of the month in German locale.
Last Updated :
29 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...