Rolling method: 65-3

Hi,

As I understood so far, ‘rolling’ method is used when we want to do some statistics on a number of consecutive values in rows. Can we also apply a function on those value like a defined lambda function?

Another question, in the page 3 of Stock market guided project, it says we can also use a for loop instead of using rolling method to calculate some indicators. would you please write some line of codes of for loop method for finding ‘avg_5’ column?

screen link: https://app.dataquest.io/m/65/guided-project%3A-predicting-the-stock-market/3/generating-indicators

Thanks

1 Like

Hello @ashkan.ghanavati92, Please provide mission link with same. More you can refer this

2 Likes

@ashkan.ghanavati92 DataFrame.iterrows is a generator which yields both the index and row (as a Series):

import pandas as pd
import numpy as np

df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})

for index, row in df.iterrows():
    print(row['c1'], row['c2'])

Output:
10 100
11 110
12 120
Or,
The df.iteritems() iterates over columns and not rows. Thus, to make it iterate over rows, you have to transpose (the "T" ), which means you change rows and columns into each other (reflect over diagonal). As a result, you effectively iterate the original dataframe over its rows when you use df.T.iteritems() .

example:

for date, row in df.T.iteritems():