0

I have a cycle_2 df with the following column names:

                 3ls    3rs     3ls      3rs    3
absolute_cost   3.00    9.40    9.40    0.00    6.00

Now I need to rename them: I did the following:

cycle_2.rename(columns={cycle_2.columns[0]:'Email', cycle_2.columns[1]:'Flash', cycle_2.columns[2]:'Sms', cycle_2.columns[3]:'UPI', cycle_2.columns[4]:'IVR'})

However its printing this out:

                 Sms    UPI     Sms     UPI     IVR
absolute_cost   3.00    9.40    9.40    0.00    6.00

I am unable to understand why is this happeneing? How can I rename them?

Expected Output:

                Email   Flash   Sms     UPI     IVR
absolute_cost   3.00    9.40    9.40    0.00    6.00
coder_bg
  • 340
  • 6
  • 20
  • have you checked https://stackoverflow.com/questions/40774787/renaming-columns-in-a-pandas-dataframe-with-duplicate-column-names – mozway May 06 '22 at 12:05
  • or simply `df.columns = ['Email', 'Flash', 'Sms', 'UPI', 'IVR']` – mozway May 06 '22 at 12:06

2 Answers2

0

This is one of the possible solutions

df.columns = ['Email', 'Flash', 'Sms', 'UPI', 'IVR']
0

cycle_2.columns = ['Email', 'Flash', 'Sms', 'UPI', 'IVR']

inkarar
  • 85
  • 9
  • it's not really useful to provide the same answer as already provided once as comment, once as answer and many more times in duplicates – mozway May 06 '22 at 12:12
  • i was typing my answer and went away for sometime and meanwhile you commented and others answered – inkarar May 06 '22 at 12:14