add columns to a data frame calculated by for loops in python -


import re #creating several new colums loop , adding them original df. #creating permutations second level of binary variables df in list_ib:     j in list_ib:         if == j:             break         else:                         bina = df[i]*df[j]             print(i,j) 

i binary columns belong data frame (df) , j same columns. have calculated multiplications each column each column. question now, how add new binary product columns original df?

i have tried:

df = df + df[i,j,bina] 

but not getting results need. suggestions?

as understand, i,j,bina not part of df. build arrays each 1 of those, each array element representing 'row' , once have rows i,j,bina ready, can concatenate this:

>>> new_df = pd.dataframe(data={'i':i, 'j':j, 'bina':bina}, columns=['i','j','bina']) >>> pd.concat([df, new_df], axis=1) 

alternatively, once have data 'i', 'j' , 'bina' collected , assuming have data each of these in separate array, can this:

>>> df['i'] = >>> df['j'] = j >>> df['bina'] = bina 

this work if these 3 arrays have many elements rows in dataframe df.

i hope helps!


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -