In pandas I am calculating means of columns and I want to rename the columns appending the string _avg.
Following the example in the answer here works: so if I do:
ss = df[col_list].mean()
ss.index = [el+"_avg" for el in col_list]
But although df[col_list].mean() is a pandas.Series type doing:
ss = df[col_list].mean().index = [el+"_avg" for el in col_list]
returns a list of strings and
ss = pandas.Series(df[col_list].mean().index = [el+"_avg" for el in col_list])
is not working at all while as in the previous link
ss = pandas.Series(df[col_list].mean(), index= [el+"_avg" for el in col_list])
changes the names but the values become NaN. (This behaviour is actually explained in the doc)
Why is that and how can I merge the two expressions a single line?