1
Answer

renaming multiple columns

Dipa Mehta

Dipa Mehta

5y
665
1
I would like to rename multiple columns with the same name by appending the number 1 for each duplicate.
 
This is what I have tried
 
select_cols = np.asarray([i for i, col in enumerate(fully_merged.columns) if 'stance' in col]) fully_merged.rename(columns={cols:'stance'+str(i) for cols in fully_merged.columns[select_cols] for i in range(1,7)}) # df.rename(columns={col: '' for col in df.columns[idx_filter]}, inplace=True)
Answers (1)