1

I have a DataFrame which looks like the following:

df
              a    a    a   b
date                              
2004-01-01    30   10   3   1
2004-01-02    30   14   4   2
2004-01-03    31   15   5   3
2004-01-04    30   15   6   3
2004-01-05    30   15   7   3

I want to rename the first a to one, the second a to two, the third a to three and b to four. I am not sure how to do this!

Cheers :)

EdChum
  • 376,765
  • 198
  • 813
  • 562
oceanbeach96
  • 604
  • 9
  • 19
  • 1
    As you're intending to overwrite all the columns then the first answer in the dupe suffices – EdChum Mar 27 '19 at 13:21
  • 1
    Use `pip` to install the `num2words` package. `from num2words import num2words`, then use list comprehension to assign new column names: `df.columns = [num2words(x + 1) for x in np.arange(df.shape[1])]` – Chris Adams Mar 27 '19 at 13:35

0 Answers0