Longshanks
Longshanks

Reputation: 23

dataframe.all() returning True when condition not met

I have a dataframe:

enter image description here

I only want rows with values less than 6 for example.

I enter:

dists_df.all(axis=1) < 6

and I get True for every row.

I would think everything visible in the dataframe screenshot should return False.

Thank you.

Upvotes: 0

Views: 174

Answers (1)

goalie1998
goalie1998

Reputation: 1432

You have your order of operations backwards. dists_df.all(axis=1) returns True for all rows first because each row exists completely. You then essentially run True < 6 which is true, as in this case True = 1. You have to reverse the order.

(dists_df < 6).all(axis=1)

Upvotes: 1

Related Questions