0

I have two dataframes where 1, 2, 3 is the connection between the dataframes:

              1    2    3 
2016-10-03   12   10   10 
2016-10-04   4     4    5 
......

and
     name    year
1   apple    2001
2   lemon    2002
3   kiwi     1990

The end result should be:

              apple    lemon    kiwi 
2016-10-03       12       10      10 
2016-10-04        4        4       5 
......

I can't figure out how to do this.

vestland
  • 55,229
  • 37
  • 187
  • 305
Jonas
  • 617
  • 3
  • 8
  • 22

1 Answers1

2

You can use rename, which does not require the two DataFrames to have the keys in the same order:

df1 = df1.rename(columns=df2['name'])
root
  • 32,715
  • 6
  • 74
  • 87