我正在尝试在 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
我做错了什么?
繁星淼淼
慕尼黑8549860
相关分类