I want to iterate elements from every row in dataframe A to see if all of the condition matches with the corresponding column values in dataframe B. I have a nested 'if'-only statement that goes like this:
for j,k in enumerate(A['type']):
for i,v in enumerate(B['typeMin']):
if B.typeMin.iloc[i]<= A['type'][j] <= B.typeMax.iloc[i]:
if B.seasonMin.iloc[i]<= A['seasons'][j] <= B.seasonMax.iloc[i]:
if B.volMin.iloc[i]<= A['Total Volume'][j] <= B.volMax.iloc[i]:
if B.bagsMin.iloc[i]<= A['Total Bags'][j] <= B.bagsMax.iloc[i]:
if B.monthMin.iloc[i]<= A['month'][j] <= B.monthMax.iloc[i]:
if B.yearMin.iloc[i]<= A['year'][j] <= B.yearMax.iloc[i]:
do this
Is there an elegant and faster way to do this? Thanks!
Aucun commentaire:
Enregistrer un commentaire