0

I have a dataset train with more than 16k observation.I have a variable fare_amount and i want to filter out all the negative values that are present in the variable.

  • fare_amount 0 4.5 1 16.9 2 5.7 3 7.7 4 5.3 5 12.1 6 7.5 7 16.5 9 8.9 10 0 11 5.5 12 4.1 13 7.0 . . . . 16065
train.isnull().sum().sort_values(ascending=False)
train = train.drop(train[train.isnull().any(1)].index, axis = 0)
from collections import Counter
Counter(int(train['fare_amount'])<0)
```TypeError: cannot convert the series to <class 'int'>

want to remove all the values that are less than 0
keep getting an error
TypeError: cannot convert the series to <class 'int'>
  • You need to look at your data and inspect its various types when you see an error like that. – Mike May 29 '19 at 20:13

1 Answers1

0

I don't know how the Counter class works, but I believe the following should work for removing negative numbers from the fare_amount list:

tempList = [item for item in fare_amount if item >= 0]
fare_amount = tempList
  • Ran it again getting an error saying variable fare_amount is not defined.If you show me in a code that will be very helpful. – Chetan Goswami May 30 '19 at 09:20