As far as i know pandas usage bitwise "&" "|" and each condition have to be wrapped in a "()"

For e.g. following works

data_query = data<(data<"year"> >= 2005) & (data<"year"> But the same query without appropriate brackets will certainly not work

data_query = data<(data<"year"> >= 2005 & data<"year"> So attempt over measures to remove your issue.


You are watching: The truth value of a dataframe is ambiguous. use a.empty, a.bool(), a.item(), a.any() or a.all().

*
answeredNov 11, 2019AbhijitJ38.6k points
even after applying this solution my problem is not gaining resolved.--------- this is my function-----------def _transform_to_long_format(df):res = <>days = pd.to_datetime(df<"data_date">)filt = (dates = current_Date)for col in INDEX_COLS:# day worths are in exact same order that rows in the dataframework - enumeration gives correct row indexesfor i,d in enumerate(days.values):if dates.loc:raise ValueError ("Date are not correct".format(k))else:res.append(, col, df.loc>)return pd.DataFrame(res, columns=<"data_date", "index_code", "value">)It is not going to IF statement wbelow I put my filter condition which is true then ssuggest raise Error.Any suggestion?
*
commentedMay 8, 2020Kashish Sharma

Your comment on this answer:

Your name to display (optional):
Email me at this deal with if a comment is included after mine:Email me if a comment is added after mine

Solution:

Theorandandpython statements requiretruth-worths. Forpandasthese are thought about ambiguous so you have to usage "bitwise"|(or) or&(and) operations:

outcome = result<(result<"var">>0.25) | (result<"var">
The exemption is thrown when you desire to obtain theboolof apandas.Series:

As user2357112 pointed out in the comments, you cannot usage chained comparisons right here. For elementwise comparichild you have to use&. That additionally calls for making use of parentheses so that&wouldn't take precedence.

It would certainly go somepoint choose this:


mask = ((50 df<"heart rate">) & (140

In order to stop that, you can develop series for lower and also upper limits:


low_limit = pd.Series(<90, 50, 95, 11, 140, 35>, index=df.columns)high_limit = pd.Series(<160, 101, 100, 19, 160, 39>, index=df.columns)

Now you deserve to slice it as follows:


df<"class"> = np.where(mask, "excellent", "critical")


answeredMay 25, 2020Tushar Shuvro31.7k points
ask related questioncomment


See more: Value Pawn Near Me - Value Pawn & Jewelry

Your discuss this answer:

Your name to display (optional):
Email me at this attend to if a comment is included after mine:Email me if a comment is included after mine