0

I have a Dataframe with 560 columns (numbered and named from 0 to 559). I'm trying to change the names of the last 10 columns by:

df.rename({550:'label',551:'mean',552:'std',553:'var',554:'med',555:'first',556:'last',557:'range',558:'min',559:'max'}, axis='columns')

However it doesn't seem to change anything:

print(df.columns.values)
>>>[  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
  ...
 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559]
Sebastian Dengler
  • 1,258
  • 13
  • 30

1 Answers1

1

df.rename by default returns the renamed DataFrame and leaves the original DataFrame unchanged. So you can either use

df.rename(..., inplace=True)

to do the column renames in place or reassign the returned, renamed DataFrame:

df = df.rename(...)
w-m
  • 10,772
  • 1
  • 42
  • 49