1

I have 2 table:

First table

Course     Price 
English    $250
Chinese    $300
Math       $500

Second table:

Name       Course
Vivian     English
Vivian     Math
Shar       Math
Nick       Math
Tan        Chinese

I wish to have a code to get the table like this which the price column in second table is actually will refer to table one:

Name       Course      Price($)
Vivian     English     250
Vivian     Math        500
Shar       Math        500
Nick       Math        500
Tan        Chinese     300

1 Answers1

2

Use merge:

table_2.merge(table_1, on='Course')

Output:

     Name   Course Price
0  Vivian  English  $250
1  Vivian     Math  $500
2    Shar     Math  $500
3    Nick     Math  $500
4     Tan  Chinese  $300
Scott Boston
  • 147,308
  • 15
  • 139
  • 187