How to create new columns by dividing all columns in a loop?
Question:
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.
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
Answers:
If I understand the requirement, this should work
for i in list_ib:
df['clv_mean_'+i] = df[i]/df['survival_time']
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.
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
If I understand the requirement, this should work
for i in list_ib:
df['clv_mean_'+i] = df[i]/df['survival_time']