I have written down below code to add few columns dynamically in a data frame. I am adding these columns in df_new dataframe but not sure why these new columns are being added up in df_wonullcol data frame as well. Below is the code screenshot for your reference.
df_new = df_wonullcol
col_data = []
for i in df_wonullcol.columns:
if i.find('_MP')!=-1:
for j in range(len(df_wonullcol[i].index)):
col_data = df_wonullcol.loc[j,i]
col_data = col_data.split(',')
for x in col_data:
df_new.loc[j,str('Q1_MP_'+x)] = x
Thanks Matthew, your suggestion is of great help.
Also do you think that the code which i have written is efficient or is there any better way to do this?