Home > Blockchain >  comparing two columns of a row in python dataframe
comparing two columns of a row in python dataframe

Time:03-03

I know that one can compare a whole column of a dataframe and making a list out of all rows that contain a certain value with:

values = parsedData[parsedData['column'] == valueToCompare]

But is there a possibility to make a list out of all rows, by comparing two columns with values like:

values = parsedData[parsedData['column01'] == valueToCompare01 and parsedData['column02'] == valueToCompare02]

Thank you!

CodePudding user response:

It is completely possible, but I have never tried using and in order to mask the dataframe, rather using & would be of interest in this case. Note that, if you want your code to be more clear, use ( ) in each statement:

values = parsedData[(parsedData['column01'] == valueToCompare01) & (parsedData['column02'] == valueToCompare02)]
  • Related