I've been looking through the documentation
and Pandas Merging 101
, but help was nowhere to be found.
Suppose I have two Dataframes as follows
>>> df
Values Count Percentage
0 Apple 0 0
1 Banana 0 0
2 Samsung 0 0
3 Orange 0 0
>>> df2
Values Count Percentage
0 Apple 14 0.74
1 Samsung 5 0.26
And I want to merge the two Dataframes to produce the following result
>>> result
Values Count Percentage
0 Apple 14 0.74
1 Banana 0 0
2 Samsung 5 0.26
3 Orange 0 0
Keep in mind that df2
is always a subset of df
.
In other words, every Values in df2
will be guaranteed to present in the Values of df
.
Here is what I have so far
result = df.merge(df2, on='Values', how='left')
>>> result
Values Count_x Percentage_x Count_y Percentage_y
0 Apple 0 0 14.0 0.74
1 Banana 0 0 NaN NaN
2 Samsung 0 0 5.0 0.26
3 Orange 0 0 NaN NaN
But the result is kind of disappointing.
Any help would be greatly appreciated.