0

with this code i want to create boolean column check to check if the value in the column LTP is in the range of 0.10% of column val.

all values are of type float.

   df = df.assign(upper_range=lambda x: (x['val'] +(x['val'] * 0.001)))
   df = df.assign(lower_range=lambda x: ( x['val']- (x['val'] * 0.001) ) )
   df = df.assign(check=lambda x: (x['LTP'] >= x['lower_range'] & x['LTP'] <= x['upper_range']))

this code gave error

    TypeError: ufunc 'bitwise_and' not supported for the input types, 
    and the inputs could not be safely coerced to any supported types according to the casting rule 
    ''safe''

    TypeError: unsupported operand type(s) for &: 'float' and 'float'

for comparison i also tried using and instead of & for which following error occured

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

how to fix this?

1 Answer 1

1

There is not closed () correctly, need parantheses for each condition:

 df = df.assign(check=lambda x: (x['LTP'] >= x['lower_range']) & (x['LTP'] <= x['upper_range']))
Sign up to request clarification or add additional context in comments.

1 Comment

@user4599 - Unfortunately no experiece with flask, so cannot help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.