pandas.Series.dt.month_name#
- Series.dt.month_name(*args, **kwargs)[源代码]#
返回指定区域的月份名称。
- Parameters:
- localebool, default False
用于确定月份名称返回语言的区域设置。默认英语区域设置 (‘en_US.utf8’)。在 Unix 系统上,请使用终端命令
locale -a来查找您的区域设置语言代码。
- Returns:
- Series 或 Index
月份名称的 Series 或 Index。
Examples
>>> 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')