I would like to loop into a list of pandas dataframe variables, but with the possibility of choosing different index positions
raw_data = {'v1': [10,np.nan,50,30],'v2': [10,-10,50,-20],'v3':[120,-130,509,-230],'v4': [5,78,34,66]}
df = pd.DataFrame(raw_data, columns = ['v1','v2','v3','v4'])
columns = ['v1','v2','v3','v4']
#pseudo code: i+1 represents the following element in the list, after "i" element
for i in columns:
print(df[i])
print(df[i+1])
in real life I would like to do more complex operations to pairs of variables, like applying a function to v1 and v3, then v2 and v4, then v3 and v5, etc.
for instance: create a new var called 'new_varv1, which is the difference between v1 and v3. then the loop will do the same with v2 and v4, storing the result in new_varv2, etc
for i in columns:
df['new_var'+i]=df[i]-df[i+2]