pandas.DatetimeIndex.month_name #

日期时间索引。Month_name ( * args , ** kwargs ) [来源] #

返回具有指定区域设置的月份名称。

参数
locale str,可选

区域设置确定返回月份名称的语言。默认为英语区域设置 ( 'en_US.utf8')。在 Unix 系统的终端上使用命令 来查找您的区域设置语言代码。locale -a

返回
系列或索引

月份名称的系列或索引。

例子

>>> s = pd.Series(pd.date_range(start='2018-01', freq='ME', periods=3))
>>> s
0   2018-01-31
1   2018-02-28
2   2018-03-31
dtype: datetime64[ns]
>>> s.dt.month_name()
0     January
1    February
2       March
dtype: object
>>> idx = pd.date_range(start='2018-01', freq='ME', periods=3)
>>> idx
DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'],
              dtype='datetime64[ns]', freq='ME')
>>> idx.month_name()
Index(['January', 'February', 'March'], dtype='object')

使用该locale参数您可以设置不同的区域设置语言,例如:idx.month_name(locale='pt_BR.utf8')将返回巴西葡萄牙语的月份名称。

>>> idx = pd.date_range(start='2018-01', freq='ME', periods=3)
>>> idx
DatetimeIndex(['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')