【发布时间】:2021-03-24 13:25:31
【问题描述】:
我已经为这个简单的事情寻找答案一个小时了。我有一个看起来像这样的熊猫数据框:
title | price
"some text 1" 124.5
"some text 2" 543.2
"some text 3" 156.2
"some text 4" "Price N/A"
"some text 5" 216.7
我想删除不包含实际浮动价格的行。我尝试了this answer的建议:
raw_data[raw_data.price.apply(lambda x: x.isnumeric())]
我得到:
AttributeError: 'float' object has no attribute 'isnumeric'
对于如此简单的操作似乎没有任何作用。我尝试了几乎所有在堆栈和其他地方找到的答案。
【问题讨论】:
-
该错误可能表明您使用的是 Python 2。您使用的是 Python 3 吗?
-
Python 3.8 是我唯一使用的。
-
使用 isinstance(x, float) 怎么样?
-
raw_data[raw_data.price.apply(lambda x: isinstance(x, float))]
标签: python python-3.x pandas