[英]expanding mean on rows in pandas
I am trying to calculate expanding mean on rows in my dataframe using pandas. 我正在尝试使用pandas计算数据框中行的扩展均值。 All seems to be working fine if calculating for columns: 如果计算列,似乎一切正常:
>>> t = pd.DataFrame([1,2,3,4,5,np.nan])
>>> t
0
0 1.0
1 2.0
2 3.0
3 4.0
4 5.0
5 NaN
>>> t.expanding(min_periods=2, axis=0).mean()
0
0 NaN
1 1.5
2 2.0
3 2.5
4 3.0
5 3.0
however if I try the same rows, I get wrong results (seems like window of size 2 is applied all the time): 但是,如果我尝试相同的行,我会得到错误的结果(似乎总是应用大小为2的窗口):
>>> t.T
0 1 2 3 4 5
0 1.0 2.0 3.0 4.0 5.0 NaN
>>> t.T.expanding(min_periods=2, axis=1).mean()
0 1 2 3 4 5
0 NaN 1.5 2.5 3.5 4.5 NaN
seems like bug to me, but maybe I'm missing something... any clues please? 对我来说似乎是个错误,但也许我错过了什么......有什么线索吗?
It is indeed a bug, listed on github-pandas-expanding and github-pandas-rolling . 它确实是一个bug,列在github-pandas-expanding和github-pandas-rolling上 。
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.