So i have Dataframe that has around 40 columns. They contain (made up) scores for a test. The columns are now named as follows:
Student, Date, Score, Score.1, Score.2 all the way to Score.39.
We were asked to reset the column names so they match the score (change Score to Score.1, Score.1 to Score.2, Score.2 to Score.3 and so on).
My code looks like this now:
import pandas as pd
prog = pd.read_excel('File.xlsx')
for c in prog.columns:
prog[c].rename(columns = lambda x : 'Score_' + x)
Unfortunatly this does not give the output i want it to.
I was hoping someone could show me how to do this.
Thanks in advance
cols = df.columns.tolist()anddf.columns = cols[:2] + ['Score_%i' % i for i in xrange(1, len(cols[2:])+1)]?