Print Specific Rows That Are Common Between Two Dataframes
i have a dataframe (df1) like this id link 1 google.com 2 yahoo.com 3 gmail.com i have another dataframe(df2) like this: id link numberOfemployees
Solution 1:
You could try this simple solution:
df2[df2.link.isin(df1.link)]
Solution 2:
what you need is pd.merge
take a look at documentation here
import pandas as pd
df1 = pd.DataFrame(
{'id': [1, 2, 3], 'link': ["google.com", "yahoo.com", "gmail.com"]})
df2 = pd.DataFrame({'id': [1, 2, 3, 4, 5, 6],
"link": ["linkedin.com","facebook.com","gmail.com","google.com","twitter.com","yahoo.com"],
"numberOfEmployees": [15,70,90,1000,155,2]})
df1.merge(df2, on="link", suffixes=('_left', '_right'))
------------------------------------------------------
| |id_left | link |id_right | numberOfEmployees|
|---|--------|----------|---------|------------------|
|0 |1 |google.com| 4 | 1000 |
|1 |2 |yahoo.com | 6 | 2 |
|2 |3 |gmail.com | 3 | 90 |
------------------------------------------------------
Post a Comment for "Print Specific Rows That Are Common Between Two Dataframes"