0

I have two pandas dataframes:

df1 = pd.DataFrame({'foo'=[1,2,3,4,5})
df2 = pd.DataFrame({'bar'=[1,3,5], 'newCol' =[a,b,c]})

I want to add the column 'newCol' to df1 where columns df1['foo'] and df2['bar'] match.

Required output:

+-----+--------+
| foo | newCol |
+-----+--------+
| 1   | a      |
+-----+--------+
| 2   |        |
+-----+--------+
| 3   | b      |
+-----+--------+
| 4   |        |
+-----+--------+
| 5   | c      |
+-----+--------+
nautograph
  • 254
  • 2
  • 10

0 Answers0