我有一个观测值超过16k的数据集训练。我有一个fare_amount变量,我想过滤掉变量中存在的所有负值。
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'>
答案 0 :(得分:0)
我不知道Counter类是如何工作的,但是我相信以下应该可以从fare_amount列表中删除负数:
tempList = [item for item in fare_amount if item >= 0]
fare_amount = tempList