Get weekday/day-of-week for Datetime column of DataFrame

后端 未结 3 941
离开以前
离开以前 2020-12-01 09:07

I have a DataFrame df like the following (excerpt, \'Timestamp\' are the index):

Timestamp              Value
2012-06-01 00:00:00     100
2012-0         


        
3条回答
  •  不知归路
    2020-12-01 09:41

    If the Timestamp column is a datetime value, then you can just use:
    df['weekday'] = df['Timestamp'].apply(lambda x: x.weekday())

    or

    df['weekday'] = pd.to_datetime(df['Timestamp']).apply(lambda x: x.weekday())

提交回复
热议问题