0

I have a dataframe called 'vp' and in some of the rows, 'rev' is a positive float and in the others, 'rev' does not exist (NaN).

How to section this dataframe into its 2 components? I tried this

vpbook = vp[vp['rev'] > 0]              # works 
vpnonbook = vp[~vp['rev'] > 0]          # does not work 

The line that does not work yields:

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

How to do this?

5
  • vpnonbook = vp[!vp['rev'] > 0] , In R you can using ~ in python it is ! Commented Aug 30, 2018 at 22:18
  • '>0' is not the correct Test for nan or valid float, there is 'isnan' as the apptopriate function. However, your error should only be caused by lacking parantheses. To invert a boolean array, ~ has to be applied on that array, not only on the first float array: 'vpnonbook = vp[~(vp['rev'] > 0)]' - EDIT: Oh my, and @Wen is additionally right, of course, please use '!'... Commented Aug 30, 2018 at 22:21
  • SpghttCd, you are right, if you 'answer' I will accept it Commented Aug 30, 2018 at 22:24
  • Using isnull and notnull to select Commented Aug 30, 2018 at 22:35
  • I tried using isnull function but it didn't like it in the context of a Boolean mask Commented Aug 30, 2018 at 22:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.