From what I understand you want to find intercessions between the values of two columns of two dataframes distinguished.
To find intercessions you can convert the columns you want to find intercessions in ensembles.
In Python sets are unordered collections and no duplicated elements and are represented by the class set.
Intercessions can be found with the method intersection()
To facilitate in the example I calculated the intercessions in the columns age two dataframes that found on the internet:
import pandas as pd
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'last_name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze'],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, 2, 3],
'postTestScore': [25, 94, 57, 62, 70]}
df1 = pd.DataFrame(raw_data, columns = ['first_name', 'last_name', 'age', 'preTestScore', 'postTestScore'])
raw_data_2 = {'first_name': ['Sarah', 'Gueniva', 'Know', 'Sara', 'Cat'],
'last_name': ['Mornig', 'Jaker', 'Alom', 'Ormon', 'Koozer'],
'age': [53, 26, 72, 73, 24],
'preTestScore': [13, 52, 72, 26, 26],
'postTestScore': [82, 52, 56, 234, 254]}
df2 = pd.DataFrame(raw_data_2, columns = ['first_name', 'last_name', 'age', 'preTestScore', 'postTestScore'])
intercessão = set(df1['age']).intersection(set(df2['age']))
print(intercessão)
# {24, 73}
Example in Repl.it: https://repl.it/repls/MutedJuicyTraining
In your case supposing that d1 and d2 be their dataframes and that NIS Beneficiário be the name of the columns in question, would look like this:
intercessão = set(d1['NIS Beneficiário']).intersection(set(d2['NIS Beneficiário']))
Thank you. But I need to see which lines there is the intersection. I will need to consult name, county and state. Ideally the results would appear in a third dataframe.
– vivape
@vivape that identifying the lines was not discriminated in the question.
– Augusto Vasques