RDJ RDJ - 1 year ago 97
Python Question

Pandas: return dataframe where one column's values are greater than another

Apologies if this is a duplicate but I can't seem to find a working example in the pandas docs, SO or google.

How do you return a dataframe where the values of one column are greater than the values of another?

Should be something like this:


But this returns only a vector. I need the full filtered dataframe.

Answer Source

Try using query

df.query('A > B')

consider df

df = pd.DataFrame(np.random.rand(10, 2), columns=list('AB'))

enter image description here

option 1

df.query('A > B')

option 2


enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download