首页 > 解决方案 > How to reformat Panda to_period('W-MON') and have correct date?

问题描述

I am converting my date in W-MON datetime format as follow:

df['created_at'] = pd.to_datetime(df['created_at']).dt.to_period('W-MON')

The result I get are giving me week starting Tuesday and finishing Monday: 2020-05-12/2020-05-18

From the doc it seems that 'W-MON' will lead to a week starting on Monday.

Also is it possible to reformat it to only have the daterange as the week starting: 2020-05-12

标签: pandasdataframe

解决方案


你需要有额外的关键字closed="left"label="left"所以它知道从星期一开始分组而不是在星期一结束


推荐阅读