admin管理员组

文章数量:1595878

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

 

第三步:分类

df3 = df2.groupby(['时间','分类']).count()
df3
<

本文标签: 日数数据resampletoperiod