I am new to python. May I ask, for example the following codes, how do I know there is an attribute of mean function following the rolling 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. To find the methods available, I first look at the documentation for rolling()
:
Returns: a Window or Rolling sub-classed for the particular operation
In the left-hand menu, I see a link for Window . Clicking on this link shows all the available methods for 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 ).
Technically, though, you can use the builtin dir
function .
Assuming data
is a DataFrame, then
dir(data['SP500'])
will tell you that there is a rolling
method, and
dir(data.rolling(50))
will tell you that there is a mean
method.
You can also use the builtin help
function .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.