Let's say I have a data frame with these column names:
['a','b','c','d','e','f','g']
And I would like to change the names from 'c' to 'f' (actually add a row to the column name), so the column names of all data columns look like this:
['a','b','var_c_equal','var_d_equal','var_e_equal','var_f_equal','g']
Ok, firstly, I created a function that changes the column names with the row I want:
df.rename(columns=lambda x: 'or_'+x+'_no', inplace=True)
But now I really want to understand how to implement something like this:
df.loc[:,'c':'f'].rename(columns=lambda x: 'var_'+x+'_equal', inplace=True)
source
share