python - looping into different positions of a list -


i loop list of pandas dataframe variables, 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 following element in list, after "i" element in columns:     print(df[i])     print(df[i+1]) 

in real life more complex operations pairs of variables, applying function v1 , v3, v2 , v4, v3 , v5, etc.

for instance: create new var called 'new_varv1, difference between v1 , v3. loop same v2 , v4, storing result in new_varv2, etc

for in columns:     df['new_var'+i]=df[i]-df[i+2] 

if understanding question correctly, this:

ctr = 1 in columns:     print(df[i])     print(df[columns[ctr]])     ctr+=1 

Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -