to_period
第一步:数据
a = pd.date_range('8/5/2021',periods=12,freq='D')
b = ['业务线'+str(i) for i in range(1,3)]
b = np.array([random.choice(b) for i in range(len(a))])
c = np.random.randint(1, 3, size=len(a))
df = pd.DataFrame({'时间':a,'分类':b,'值':c})
df
第二步:时间转换为索引,日期转换为周 (df.to_period)
df2 = df.set_index('时间').to_period(freq='W-THU')#以周五开始--THU
df2