这是我的数据
我在做sheet2['device_create_week'] = sheet2['device_create_at'].dt.week,这是结果
device_create_at device_create_week
136 2014-08-27 17:29:23 35
245 2015-09-06 15:46:00 39
257 2014-09-29 22:26:34 40
258 2014-11-05 13:02:18 40
480 2020-02-02 17:59:54 6
481 2020-02-02 17:59:54 6
482 2020-02-02 17:59:54 6但我想
device_create_at device_create_week
136 2014-08-27 17:29:23 2014-35
245 2015-09-06 15:46:00 2015-39
257 2014-09-29 22:26:34 2014-40
258 2014-11-05 13:02:18 2014-40
480 2020-02-02 17:59:54 2020-6
481 2020-02-02 17:59:54 2020-6
482 2020-02-02 17:59:54 2020-6只要它是可绘制的,其他的解决方案也是好的,而且我每周都能看到增长。
发布于 2017-10-12 05:17:37
使用year + week
sheet2['device_create_week'] = sheet2['device_create_at'].dt.year.astype(str) + '-' +
sheet2['device_create_at'].dt.week.astype(str)
print (sheet2)
device_create_at device_create_week
136 2014-08-27 17:29:23 2014-35
245 2015-09-06 15:46:00 2015-36
257 2014-09-29 22:26:34 2014-40
258 2014-11-05 13:02:18 2014-45
480 2020-02-02 17:59:54 2020-5
481 2020-02-02 17:59:54 2020-5
482 2020-02-02 17:59:54 2020-5strftime与V的另一种解决方案
sheet2['device_create_week'] = sheet2['device_create_at'].dt.strftime('%Y-%V')
print (sheet2)
device_create_at device_create_week
136 2014-08-27 17:29:23 2014-35
245 2015-09-06 15:46:00 2015-36
257 2014-09-29 22:26:34 2014-40
258 2014-11-05 13:02:18 2014-45
480 2020-02-02 17:59:54 2020-05
481 2020-02-02 17:59:54 2020-05
482 2020-02-02 17:59:54 2020-05https://stackoverflow.com/questions/46701899
复制相似问题