首页 > 解决方案 > pd.Series.dt.weekday 与 pd.Series.dt.dayofweek 之间有区别吗?

问题描述

我在 Pandas 中度过了一段时间,并且已经看到有两种方法可以从时间戳中提取星期几整数。这些是pd.Series.dt.weekdaypd.Series.dt.dayofweek

文档说两者都返回:Series 或 Index 包含整数,表示Monday=0星期几与,所在的星期几Sunday=6

我是否遗漏了什么或者这两个功能实际上是相同的?

在“另请参阅”部分中,它确实将其他功能描述为别名。这能回答我的问题吗?

标签: pythonpandas

解决方案


你解决了你的问题:

 |  dayofweek
 |      The day of the week with Monday=0, Sunday=6.
 |      
 |      Return the day of the week. It is assumed the week starts on
 |      Monday, which is denoted by 0 and ends on Sunday which is denoted
 |      by 6. This method is available on both Series with datetime
 |      values (using the `dt` accessor) or DatetimeIndex.
 |      
 |      Returns
 |      -------
 |      Series or Index
 |          Containing integers indicating the day number.
 |      
 |      See Also
 |      --------
 |      Series.dt.dayofweek : Alias.
 |      Series.dt.weekday : Alias.  # <-- YES IT'S AN ALIAS
 |      Series.dt.day_name : Returns the name of the day of the week.

源代码

    dayofweek = day_of_week
    weekday = dayofweek

推荐阅读