I am trying to match two columns (ie: values from Col1 and Col2 from Df1 match with ColA and Col2 from Df2) and do a merge on that. I'm having trouble with the merge syntax, I currently have merged_df = df1.merge(df2,how='inner',left_on=['Col1,Col2'],right_on=['ColA,Col2])
but it doesn't seem to be working (it's giving me less than what I'm expecting). Any tips?
Just as you tried, it returns the correct results:
df1.merge(df2, how='inner',left_on=['Col1','Col2'], right_on=['ColA','Col2'])
It's an inner join (keeping only the matches) between both datasets, based on the available couples of ['Col1','Col2']
and ['ColA','Col2']
. The matches are on rows 1 to 6 (or 0 to 5) in both datasets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.