pandas.Series.dt.day_name #
- 系列.dt。day_name ( * args , ** kwargs ) [来源] #
返回具有指定区域设置的日期名称。
- 参数:
- locale str,可选
区域设置确定返回日期名称所用的语言。默认为英语区域设置 (
'en_US.utf8'
)。在 Unix 系统的终端上使用命令 来查找您的区域设置语言代码。locale -a
- 返回:
- 系列或索引
日期名称的系列或索引。
例子
>>> s = pd.Series(pd.date_range(start='2018-01-01', freq='D', periods=3)) >>> s 0 2018-01-01 1 2018-01-02 2 2018-01-03 dtype: datetime64[ns] >>> s.dt.day_name() 0 Monday 1 Tuesday 2 Wednesday dtype: object
>>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3) >>> idx DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') >>> idx.day_name() Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
使用该
locale
参数,您可以设置不同的区域设置语言,例如:idx.day_name(locale='pt_BR.utf8')
将返回巴西葡萄牙语的日期名称。>>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3) >>> idx DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') >>> idx.day_name(locale='pt_BR.utf8') Index(['Segunda', 'Terça', 'Quarta'], dtype='object')