how to rename columns in pandas using a list
You need generate new columns names - first and second value from old one and another from list
:
df.columns = df.columns[:2].tolist() + namesList
Sample:
df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6], 'C':[7,8,9], 'D':[1,3,5], 'E':[5,3,6], 'F':[7,4,3]})print (df) A B C D E F0 1 4 7 1 5 71 2 5 8 3 3 42 3 6 9 5 6 3namesList = ['K','L','M','N']df.columns = df.columns[:2].tolist() + namesListprint (df) A B K L M N0 1 4 7 1 5 71 2 5 8 3 3 42 3 6 9 5 6 3