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
  • 43,687
  • 29
  • 146
  • 249
Jonas
  • 575
  • 3
  • 5
  • 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
  • 29,713
  • 5
  • 67
  • 80