Python 熊猫:dt.dayofweek显示不正确的值

Python 熊猫:dt.dayofweek显示不正确的值,python,pandas,datetime,dayofweek,Python,Pandas,Datetime,Dayofweek,我很难理解为什么一周中的某一天会将一个星期五解释为第四周的某一天 一些简单的数据: import pandas as pd # Simple time series data: series = pd.Series({"2017-02-20": 1, '2017-02-21':2, '2017-02-22':3, '2017-02-23': 4, '2017-02-24':5}) datetime = pd.to_datetime(series.index) # turn series in

我很难理解为什么一周中的某一天会将一个星期五解释为第四周的某一天

一些简单的数据:

import pandas as pd

# Simple time series data:
series = pd.Series({"2017-02-20": 1, '2017-02-21':2, '2017-02-22':3, '2017-02-23': 4, '2017-02-24':5})
datetime = pd.to_datetime(series.index)

# turn series in to dataframe:
df = pd.DataFrame(series.values, index=datetime)
现在,如果我们调用
argmax()
并询问一周中的哪一天:

df[0].argmax().dayofweek

# 4
所以说星期五是一周中的第四天,这显然是错误的

我做错什么了吗?我在这个问题上花的时间太长了


我可以大胆猜测,这个函数没有正确实现,但如果它不能计算任意日期时间索引的星期几,它就有点破坏了我的对象

星期一=0,星期日=6的一周中的某一天

因此,是的,星期五将被标记为4。如果您不喜欢将数字映射到一周中的某几天,您可以随时将此映射映射到您喜欢的任何位置,例如,如果您希望将星期日->星期六作为1->7

>>> custom_map = dict(zip(range(7), [2, 3, 4, 5, 6, 7, 1]))

>>> custom_map
{0: 2, 1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 1}
虽然我并不认为这样做有什么价值