danza
danza

Reputation: 12231

How to select rows using relationships between their values in Pandas

Let us say that i have a data frame with the following content:

input,output
30,10
13,33
86,37

how do i select the rows where input is greater than output?

Upvotes: 0

Views: 70

Answers (1)

EdChum
EdChum

Reputation: 393893

Just pass the boolean comparison as a mask:

In [130]:
df[df['input']>df['output']]

Out[130]:
   input  output
0     30      10
2     86      37

There is also the gt which means greater than:

In [133]:
df[df['input'].gt(df['output'])]

Out[133]:
   input  output
0     30      10
2     86      37

Upvotes: 1

Related Questions