- API reference
- pandas.DatetimeIndex
- pandas.Datet...
pandas.DatetimeIndex.month_name#
- DatetimeIndex.month_name(*args,**kwargs)[source]#
Return the month names with specified locale.
- Parameters:
- localestr, optional
Locale determining the language in which to return the month name.Default is English locale (
'en_US.utf8'). Use the commandlocale-aon your terminal on Unix systems to find your localelanguage code.
- Returns:
- Series or Index
Series or Index of month names.
Examples
>>>s=pd.Series(pd.date_range(start='2018-01',freq='ME',periods=3))>>>s0 2018-01-311 2018-02-282 2018-03-31dtype: datetime64[ns]>>>s.dt.month_name()0 January1 February2 Marchdtype: object
>>>idx=pd.date_range(start='2018-01',freq='ME',periods=3)>>>idxDatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], dtype='datetime64[ns]', freq='ME')>>>idx.month_name()Index(['January', 'February', 'March'], dtype='object')
Using the
localeparameter you can set a different locale language,for example:idx.month_name(locale='pt_BR.utf8')will return monthnames in Brazilian Portuguese language.>>>idx=pd.date_range(start='2018-01',freq='ME',periods=3)>>>idxDatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], dtype='datetime64[ns]', freq='ME')>>>idx.month_name(locale='pt_BR.utf8')Index(['Janeiro', 'Fevereiro', 'Março'], dtype='object')
On this page