'How to insert value of a column from one dataframe into other using df.isin?
I have two dataframes. df1 as
company_id | URL | found_keywords | no of urls | company name
IQ137156215 [list of urls] insurance 15 BBT
IQ3806173 [list of urls] insurance 9 Audi
df2 as
company name | website | Excel company id
Honda www.honda.com HO23455
BBT www.bbtgrp.com IQ137156215
Yamaha www.yamaha.com YM126736
Audi www.audi.com IQ3806173
based on these two dataframe's I would like to have a few records from df2 in df1 where company id from df2 is not in df1. Like this
company_id | URL | found_keywords | no of urls | company name
IQ137156215 [list of urls] insurance 15 BBT
IQ3806173 [list of urls] insurance 9 Audi
HO23455 [list of urls] insurance 4 Honda
YM126736 NaN NaN 0 Yamaha
using np.where I tried to check if a column's value of a dataframe is present in another. If it is then it simply adds it.
here is how I tried it.
np.where(df2['Excel Company ID'].isin(df1['company_id']), df2['Excel Company ID'], "")
which resulted in a
ValueError: Length of values (220) does not match length of index (4)
how do I achieve the task? Please help me out. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
