【发布时间】:2018-11-21 18:26:09
【问题描述】:
我正在尝试在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
我做错了什么?
【问题讨论】:
标签: python python-3.x python-2.7 user-defined-types isinstance