我的数据帧如下所示:
times = pd.to_datetime(pd.Series(['2020-08-05','2020-08-12', '2020-08-16', '2020-08-22', '2020-08-30', '2020-09-11', '2020-09-20']))
event = [100, 90, 77, 62, 39, 30, 30]
df = pd.DataFrame({'Active_Covid_Cases': event}, index=times)我想分析一下趋势是如何一周一周地变化的。
我的预期输出应该如下所示:(WW: Work Week)
WW Active_Case times
0 100 2020-08-05
1 90 2020-08-12
2 .. 2020-08-19
3 .. 2020-08-26WW0对应于第一个日期(2020-08-05),因此,WW1将是2020-08-12,依此类推……
我正在使用:df2 = df.resample('W')做重采样,但是,为了进入工作周格式,还需要添加什么?
发布于 2020-04-21 18:48:39
df2 = df.resample('7D', closed='right', label='right').sum()
df2.reset_index(inplace=True, drop=False)
df2.rename(columns={'index': 'times'}, inplace=True)
df2.reset_index(inplace=True, drop=False)
df2.rename(columns={'index': 'WW'}, inplace=True)
df2
WW times Active_Covid_Cases
0 0 2020-08-05 100
1 1 2020-08-12 90
2 2 2020-08-19 77
3 3 2020-08-26 62
4 4 2020-09-02 39
5 5 2020-09-09 0
6 6 2020-09-16 30
7 7 2020-09-23 30https://stackoverflow.com/questions/61341032
复制相似问题