mercredi 9 janvier 2019

Conditional for loop in python

I have two DataFrames: dfSide0 and dfSide1 that have the same columns but different number of rows. What I want to do is get the minimum of all possible subtractions between the values of dfSide0['columny'] and dfSide1['columny'] but only when the condition dfSide0['columnx'] = dfSide1['columnx'] is True.

So I do the following (in pseudocode):

list = []
if dfSide0['columnx'] = dfSide1['columnx']:
    for i in dfSide0['columny']:
        c = min(abs(i - dfSide1['columny']))
        list.append(c)

The for loop runs fine, but when I add the if statement I get the following error: "ValueError: Can only compare identically-labeled Series objects"

what am I missing here?

Aucun commentaire:

Enregistrer un commentaire