Im trying to replace the column names of a dataframe (sens_second_X) based on the strings in a list (updated_fist_stage) being substrings to the column names.
updated_fist_stage = ['ccc_230', 'LN_S_P500', 'mf_100']
and
sens_second_X.columns = ['resid', 'ccc_230_TY',
EQ_ETF',
'LN_S_P500_changes', 'mf_100_equity', 'inflows_2009',
'inflows_2010']
I try to do this as follows:
def renaming_fun(x):
for var in updated_fist_stage:
if var in x:
return var
return x
sens_second_X.columns = map(renaming_fun, sens_second_X.columns)
but I get that only ccc_230 has been renamed in the dataframe and the output is as follows:
sens_second_X.columns = ['resid', 'ccc_230',
EQ_ETF',
'LN_S_P500_changes', 'mf_100_equity', 'inflows_2009',
'inflows_2010']