아래 사이트에 잘 나옴
merge, join, left, right
https://www.shanelynn.ie/merge-join-dataframes-python-pandas-index-1/
# First, add the platform and device to the user usage - use a left join this time.
result = pd.merge(user_usage,
user_device[['use_id', 'platform', 'device']],
on='use_id',
how='left')
# At this point, the platform and device columns are included
# in the result along with all columns from user_usage
# Now, based on the "device" column in result, match the "Model" column in devices.
devices.rename(columns={"Retail Branding": "manufacturer"}, inplace=True)
result = pd.merge(result,
devices[['manufacturer', 'Model']],
left_on='device',
right_on='Model',
how='left')
print(result.head())
https://www.datascienceexamples.com/joins-with-pandas/
Joins with Pandas
Please follow and like us: For those of you who are familiar with SQL, you will recognize the logic and functionality behind the Pandas merge feature. However, if you are not familiar with SQL, or[...]
www.datascienceexamples.com
한참을 찾았습니다. Pandas 의 두 dataframe 의 차집합
df = pd.merge(dfA, dfB, on=['a','b'], how="outer", indicator=True)
df = df[df['_merge'] == 'left_only']
One liner :
df = pd.merge(dfA, dfB, on=['a','b'], how="outer", indicator=True
).query('_merge=="left_only"')
댓글