【发布时间】:2019-11-12 18:28:11
【问题描述】:
我有一个数据框,其中包含一些 Jira 问题,我试图按周和状态对其进行排序,并获取每周每个状态的项目数量。因此,例如,我的数据框的两周目前看起来像这样:
2019-11-04 Authorize Work 4
Await Work 1
Check Work 4
Closed 4
Confirm Work 3
Do Work 3
2019-11-11 Authorize Work 6
Do Work 2
我已经做到了这一点:
# Remove the time portion of the date
df['creation_date'] = df['creation_date'].dt.date
# Set the date to be a week long delta
df['creation_date'] = pd.to_datetime(df['creation_date']) - pd.to_timedelta(7, unit='d')
# Sort together by creation date within the week and the status, and do a count
endf = df.groupby([pd.Grouper(key="creation_date", freq="W-MON"), "status"]).size()
您会注意到第二周只有两个状态,而第一周有六个。这是因为在第二周,缺少状态的 jira 问题为零。有没有办法让 size 函数包含计数为零的缺失状态,以便每周内的数据是同一组状态?
【问题讨论】:
标签: python pandas dataframe data-science