groupby.count in pandas有条件
我有13年的天气数据,每年有154天(仅对夏季感兴趣),我想从中获得每年的干燥天数。这意味着我有一个很棒的数据(DF)集,我想收缩(DF_CH)。我已经完成了每年的总降雨:
df_Ch = df.groupby(by = ["distrito", "year"], as_index=False)["Chuvia"].sum()
我现在每年都在尝试总干日:
df_Ds = df.groupby(by = ["distrito", "year"], as_index=False)[when "Chuvia" == 0].count()
当然,它无效 我花了几个小时而没有成功地尝试得到一些建议?
I have weather data from 13 years, with 154 days each year (only interested in summer days), from which I would like to get the number of dry days occurred each year. This means I have a great data (df) set that I want to shrink (df_Ch). I've already done with the total rain per year:
df_Ch = df.groupby(by = ["distrito", "year"], as_index=False)["Chuvia"].sum()
I'm now trying with total dry days per year:
df_Ds = df.groupby(by = ["distrito", "year"], as_index=False)[when "Chuvia" == 0].count()
Of course, it didn't work
I spent some hours without success trying to get something... Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在使用
groupby
之前应用条件,这样您在分组之前就已经有了“过滤后的”df。Apply the condition before using
groupby
, so you will already have your "filtered" df before grouping it.