Q: Pandas DataFrame - match rows within a group I have two dataframes as below, which are separated by tab:
df1: 
steve jobs    12344    
john hancock  12344    
john peter    42154    
...           ...

df2:
steve jobs    2004    12344    
john smith    2004    12344    
joan clements 2004    12344     
judy rodes    2044    12344     
amber bright  2004    98999     
stephanie t   2004    98999    
...           ...

The code below allows me to calculate the token_sort_ratio of the first name in df1 to all records in df2 (i.e. steve jobs in df1 to steve jobs, john smith, joan clements, judy rodes, amber bright and stephanie t in df2)
import pandas as pd
from fuzzywuzzy import fuzz

cols = ['name','firmID']
df1=pd.read.csv(r'fileone.txt', sep='\t', names=cols)
df1=df1.set_index('names')

cols = ['name', 'year', 'firmID']
df2=pd.read.csv(r'filetwo.txt', sep='\t', names=cols)
df2=df2.set_index('names')

for index1, rows in df1.iterrows():
    for index2, rows in df2.iterrows():
        ans = fuzz.token_sort_ratio(index1, index2)
        print (index1, index2, ans)

However, this takes up quite a lot of time and I am wondering if I can just calculate scores for names in df2 that have the same firmID as names in df1. (i.e. calculations to be done for steve jobs in df1 to steve jobs, john smith, joan clements and judy rodes in df2 since they share the same firmID (12344), as well as john hancock in df1 to steve jobs, john smith, joan clements and judy rodes in df2). 
I tried this:
grouped=df1.groupby('firmID').groups
grouped2=df2.groupby('firmID').groups
for index1, rows, group in grouped.iterrows():
    for index2, rows, group in grouped2.iterrow():
       ans = fuzz.token_sort_ratio(index1, index2)
       print (index1, index2, ans)

The error I got was: 

AttributeError: 'dict' object has no attribute 'iterrows'

Did I do something incorrect by using groupby? Any help on this will be much appreciated!
