Hugo
Hugo

Reputation: 1688

How do I slice a pandas dataframe based on a condition?

When I use the following code:

frioMurteira = data.loc[(data["POM"] == "Murteira" & data["TMP"] > 7.2), ["DTM","TMP"]]

I get the following error:

cannot compare a dtyped [float64] array with a scalar of type [bool]

Could you help me?

Thank you

Upvotes: 6

Views: 23287

Answers (1)

Alvaro Fuentes
Alvaro Fuentes

Reputation: 17455

I think there is an error with your braces, try this:

frioMurteira = data.loc[(data["POM"] == "Murteira") & (data["TMP"] > 7.2), ["DTM","TMP"]]

Upvotes: 15

Related Questions