I have a dataframe with two columns: price and pattern (can be 0 if absent or 1 if exists).
Price Pattern
10 0
12 1
15 0
11 0
9 0
First, i need to iterate to find row with existing pattern (pattern = 1), then
- compare price in current row (12) with price in next row (15). Basically i need to know how price changed (15 - 12) and put result in new column "diff_1_tf" so later i can use all of these values to see average / overall picture.
- compare price in current row (12) with price in third row from current row (9 - 12) and put result in new column "diff_3_tf".
I know that shift can be usefull but i just cant understand how to make it work in my case. I'm stuck here. Please help.
new_df = df[['price', "pattern"]].copy()
for row in new_df["pattern"]:
if row == 1:
print(row)
Update: finally i solved my problem with new_df.iterrows() and index manipulations