Get week start date (Monday) from a date column in Python (pandas)?

前端 未结 5 912
孤城傲影
孤城傲影 2020-12-15 17:48

I have seen a lot of posts about how you can do it with a date string but I am trying something for a dataframe column and haven\'t got any luck so far. My current method is

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 18:24

    Another alternative:

    df['week_start'] = df['myday'].dt.to_period('W').apply(lambda r: r.start_time)
    

    This will set 'week_start' to be the first Monday before the time in 'myday'.

提交回复
热议问题