I have 2 Dataframes, fit and mass. They only have one similar column, 'CATAID'. The fit Dataframe contains information about the whole experiment. The mass one, however, only contains a small population of the experiment.
For my work, I need the information in the fit DataFrame, but for the 'CATAID' values in the mass Dataframe. I need to loop over the column values in fit and pick rows that match with CATAID values in mass.
I'm using the following loop,
file=pd.DataFrame()
for i in mass.index:
cataid_m=mass.loc[i,'CATAID']
for j in fit.index:
cataid_f=fit.loc[j,'CATAID']
if cataid_m==cataid_f:
file[j]=fit.iloc[j]
My only concern is the amount of time this loop takes. I was wondering if anyone has any suggestions on how to improve this loop?