I'm a newbie to pandas, and suspect this has a simple answer, but it's stumping me right now. I want to select the rows from multiple dataframes (with same columns) where a value in one column occurs in all of the dataframes.
So if I have the following:
import numpy as np import pandas as pd df1 = pd.DataFrame({'Col1'['Adams','Baker','Cash','Jones','Thomas'],\ 'Col2': ['A','B','C','D','E'],'Col3':[10,11,12,13,14]}) df2 = pd.DataFrame({'Col1':['Adams','Cash','Fox','Jones','Johnson'],\ 'Col2': ['D','E','F','G','H'],'Col3':[40,50,60,70,80]}) df3 = pd.DataFrame({'Col1': ['Adams','Barns','Jones','Smith','Thomas'],\ 'Col2':['F','G','J','L','M'],'Col3':[21,21,22,23,24]}) print df1 print df2 print df3 Giving:
Col 1 Col2 Col3 0 Adams A 10 1 Baker B 11 2 Cash C 12 3 Jones D 13 4 Thomas E 14 Col1 Col2 Col3 0 Adams D 40 1 Cash E 50 2 Fox F 60 3 Jones G 70 4 Johnson H 80 Col1 Col2 Col3 0 Adams F 21 1 Barns G 21 2 Jones J 22 3 Smith L 23 4 Thomas M 24 I want to end up with:
Adams A 10 Adams D 40 Adams F 21 Jones D 13 Jones G 70 Jones J 22 Is there a succinct way to do this?