gpt4 book ai didi

pandas - Pandas "expanding window"函数是什么?

转载 作者:行者123 更新时间:2023-12-03 14:46:20 27 4
gpt4 key购买 nike

Pandas 文档列出了一堆“扩展窗口函数”:

http://pandas.pydata.org/pandas-docs/version/0.17.0/api.html#standard-expanding-window-functions

但我无法从文档中弄清楚他们做了什么。

最佳答案

您可能想阅读 this Pandas docs :

A common alternative to rolling statistics is to use an expanding window, which yields the value of the statistic with all the data available up to that point in time.

These follow a similar interface to .rolling, with the .expanding method returning an Expanding object.

As these calculations are a special case of rolling statistics, they are implemented in pandas such that the following two calls are equivalent:


In [96]: df.rolling(window=len(df), min_periods=1).mean()[:5]
Out[96]:
A B C D
2000-01-01 0.314226 -0.001675 0.071823 0.892566
2000-01-02 0.654522 -0.171495 0.179278 0.853361
2000-01-03 0.708733 -0.064489 -0.238271 1.371111
2000-01-04 0.987613 0.163472 -0.919693 1.566485
2000-01-05 1.426971 0.288267 -1.358877 1.808650

In [97]: df.expanding(min_periods=1).mean()[:5]
Out[97]:
A B C D
2000-01-01 0.314226 -0.001675 0.071823 0.892566
2000-01-02 0.654522 -0.171495 0.179278 0.853361
2000-01-03 0.708733 -0.064489 -0.238271 1.371111
2000-01-04 0.987613 0.163472 -0.919693 1.566485
2000-01-05 1.426971 0.288267 -1.358877 1.808650

关于pandas - Pandas "expanding window"函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45370666/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com