在过去的30天里,我必须计算温度超过32摄氏度的天数。我正在尝试使用滚动平均值。问题是一个月的天数各不相同。
weather_2['highTemp_days'] = weather_2.groupby(['date','station'])['over32'].apply(lambda x: x.rolling(len('month')).sum())
weather_2有66个台站,date从1950年到2020年变化,over32是布尔数据。如果该日期的临时温度大于32,则为1,否则为零。月份是从日期数据(即weather_2['month'] = weather_2['date'].dt.month )中提取的
发布于 2021-08-02 15:01:43
我用这个
weather_2['highTemp_days'] = weather_2.groupby(['year','station'])['over32'].apply(lambda x: x.rolling(30).sum())
这个问题是我按日期分组的。这就是为什么答案是错误的。
https://stackoverflow.com/questions/68623643
复制相似问题