我将尝试编写一个函数,它与Excel中的isnumber[column]函数相等。
数据集:
feature1 feature2 feature3
123 1.07 1
231 2.08 3
122 ab 4
111 3.04 6
555 cde 8
feature1: integer dtype
feature2: object dtype
feature3: integer dtype
我尝试了这段代码
for item in df.feature2.iteritems():
if isinstance(item, float):
print('yes')
else:
print('no')
我得到的结果是:
no
no
no
no
no
但我希望您能将结果呈现为:
yes
yes
no
yes
no
当我尝试检查单个feature2值的类型时,看到的是这样的:
type(df.feature2[0]) = str
type(df.feature2[1]) = str
type(df.feature2[2]) = str
type(df.feature2[3]) = str
type(df.feature2[4]) = str
But clearly 0,1,3 should be shown as float, but they show up as str
我做错了什么?