Dipa Mehta

Dipa Mehta

  • 144
  • 12.6k
  • 499.9k

renaming multiple columns

Nov 20 2019 6:01 AM
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)