Home > OS >  How to create new columns by dividing all columns in a loop?
How to create new columns by dividing all columns in a loop?

Time:12-17

i'm having a trouble in my code. i just want to create new columns by dividing all columns / survival_time and after i need to add new columns as (clv_mean_xxx) to main dataframe.

enter image description here

here is my code.

list_ib = ['actor_masterylevel', 'churn_yn', 'old_value2_num', 'old_value3_num','old_value4_num', 'time']

for i in list_ib:
    for j in list_ib:
        if i == j:
            break
        else:
            df = df[i] * df['survival_time']
            df['clv_'   str(i)   '_'   str(j)] = df

CodePudding user response:

If I understand the requirement, this should work

for i in list_ib:
    df['clv_mean_' i] = df[i]/df['survival_time']
  • Related