ValueError: The truth value of a DataFrame is ambiguous in Python
Dung Do Tien May 30 2021 672
I have an issue when I trying to filter the result dataframe with an
I want to extract all column
rsl_name values that satisfy the condition above 10 and below -10.
result = result[(result['rsl_name'] > 10) or (result['rsl_name'] < -10)]
The logic above give me an error is ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Please tell me why and how to fix it?
Have 2 answer(s) found.
Nguyen Quoc Viet May 30 2021
andpython statements require
pandasthese are considered ambiguous so you should use "bitwise"
result = result[(result['var']>0.25) | (result['var']<-0.25)]
In general. You need to change
Aa May 30 2021
Well pandas use bitwise
|and each condition should be wrapped in a
For example following works:
data_query = data[(data['year'] >= 200) | (data['year'] <= 250)]
I hope it resolves the issue for you.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.