A very simple example just for understanding.
The goal is to calculate the values of a pandas DataFrame column depending on the results of a rolling function from another column.
I have the following DataFrame:
import numpy as np
import pandas as pd
s = pd.Series([1,2,3,2,1,2,3,2,1])
df = pd.DataFrame({'DATA':s, 'POINTS':0})
df
Note: I don't even know how to format the Jupyter Notebook results in the Stackoverflow edit window, so I copy and paste the image, I beg your pardon.
The DATA column shows the observed data; the POINTS column, initialized to 0, is used to collect the output of a "rolling" function applied to DATA column, as explained in the following.
Set a window = 4
nwin = 4
Just for the example, the "rolling" function calculate the max.
Now let me use a drawing to explain what I need.
For every iteration, the rolling function calculate the maximum of the data in the window; then the POINT at the same index of the max DATA is incremented by 1.
The final result is:
Can you help me with the python code?
I really appreciate your help.
Thank you in advance for your time,
Gilberto
P.S. Can you also suggest how to copy and paste Jupyter Notebook formatted cell to Stackoverflow edit window? Thank you.