Import NumPy under the alias np
.
import numpy as np
Import pandas under the alias pd
.
import pandas as pd
Using df1
and df2
as specified below, merge them using the key key
. Specify how = inner
as an argument.
df1 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],
'value': [1, 2, 3, 5]})
df2 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],
'value': [5, 6, 7, 8]})
#Solution goes here
pd.merge(df1, df2, on='key', how='inner')
key | value_x | value_y | |
---|---|---|---|
0 | foo | 1 | 5 |
1 | foo | 1 | 8 |
2 | foo | 5 | 5 |
3 | foo | 5 | 8 |
4 | bar | 2 | 6 |
5 | baz | 3 | 7 |