简体   繁体   English

python 中的简单移动平均线

[英]simple moving average in python

I am new to python.我是 python 的新手。 May I ask, for example the following codes, how do I know there is an attribute of mean function following the rolling function?请问,例如下面的代码,我怎么知道在滚动function之后有一个mean function的属性? (I am not sure if I said this correctly syntaxically) Thank you guys. (我不确定我的语法是否正确)谢谢你们。

data['SMA50'] = data['SP500'].rolling(50).mean()

I assume that data is a pandas data frame.我假设data是 pandas 数据帧。 To find the methods available, I first look at the documentation for rolling() :为了找到可用的方法,我首先查看rolling()的文档:

Returns: a Window or Rolling sub-classed for the particular operation返回:为特定操作分类的 Window 或 Rolling 子类

In the left-hand menu, I see a link for Window .在左侧菜单中,我看到了Window的链接。 Clicking on this link shows all the available methods for Rolling .单击此链接将显示Rolling的所有可用方法。

In general, in order to understand an API (in this case, Pandas), you need to read its documentation (in one of many forms, perhaps a tutorial ).通常,为了理解 API(在本例中为 Pandas),您需要阅读其文档(在许多 forms 之一,也许是教程)。

Technically, though, you can use the builtin dir function .不过,从技术上讲,您可以使用内置dir function

Assuming data is a DataFrame, then假设data是DataFrame,那么

dir(data['SP500'])

will tell you that there is a rolling method, and会告诉你有rolling的方法,并且

dir(data.rolling(50))

will tell you that there is a mean method.会告诉你有一个mean方法。

You can also use the builtin help function .您还可以使用内置help function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM