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?

Mark Ginsburg
  • 2,139
  • 4
  • 17
  • 31
  • vpnonbook = vp[!vp['rev'] > 0] , In R you can using ~ in python it is ! – BENY Aug 30 '18 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 '!'... – SpghttCd Aug 30 '18 at 22:21
  • SpghttCd, you are right, if you 'answer' I will accept it – Mark Ginsburg Aug 30 '18 at 22:24
  • Using isnull and notnull to select – BENY Aug 30 '18 at 22:35
  • I tried using isnull function but it didn't like it in the context of a Boolean mask – Mark Ginsburg Aug 30 '18 at 22:38

0 Answers0