定期进行平均
尽管我认为这很容易,但这可能是一个很难的问题。 所以问题是我想计算N个区间的平均值。
为了简化我的数据,原始数据就像
Group | Animal |
---|---|
1 | 6 |
3 | 5 |
2 | 4 |
4 | nan |
5 | 4 |
4 | nan |
我想每 3 步取平均值,这意味着期望的 df[Group] 显示在三行中
Group
2.5 -->(1+4)/2
4 --> (3+5)/2
3 --> (2+4)/2
另一个问题是遇到 NaN 值,所以如果它有 NaN 值,我们只计算没有 NaN 的值(当然不显示 NaN) 因此,df[Animal]
中的理想结果将
Animal
6 --> (only 6, NaN cannot be calculated)
4.5 --> (5+4)/2
4 --> (4, NaN cannot be calculated)
显示在三行中 任何解决它的想法,我很感激!
This might be a tough question though I thought it was easy.
So the problem is that I want to calculate the mean in N interval.
To simplify my data, the original data is like
Group | Animal |
---|---|
1 | 6 |
3 | 5 |
2 | 4 |
4 | nan |
5 | 4 |
4 | nan |
And I would like to do average with each 3 steps,which means that the expecting df[Group]
shows in three rows
Group
2.5 -->(1+4)/2
4 --> (3+5)/2
3 --> (2+4)/2
And the other problem is encountering NaN value, so if it has NaN value, we just calculate the value without NaN (and of course not showing NaN)
Thus, the ideal result in df[Animal]
will be
Animal
6 --> (only 6, NaN cannot be calculated)
4.5 --> (5+4)/2
4 --> (4, NaN cannot be calculated)
shows in three rows
Any ideas to solve it, I appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用
%
:余数You can try with
%
: remainder