I found an alternate answer here
link
我的数据帧当前看起来像这样
date new_cases new_deaths new_tests year month day weekday
0 2019-12-31 0.0 0.0 NaN 2019 12 31 1
1 2020-01-01 0.0 0.0 NaN 2020 1 1 2
2 2020-01-02 0.0 0.0 NaN 2020 1 2 3
我想通过一个代码来平均出工作日和周末的“新案例” 我的代码目前看起来像这样,但我只能通过1个条件,即'==6'。我想通过多个条件,例如,==(4,5,6)
covid_df[covid_df.weekday == 6].new_cases.mean()
有线索吗
您可以将
groupby()
日期设置为工作日或周末。下面的代码源代码并演示了这一点我想你在找
isin
:选择
weekday
在days
列表中的行;然后选择new_cases
列相关问题 更多 >
编程相关推荐