Python 是否将浮点列视为非数字列?

Python 是否将浮点列视为非数字列?,python,pandas,Python,Pandas,为什么熊猫会在两个类型均为float64的列上为descripe()打印不同类型的输出 我的密码是: print '\nBRANDED\n' print df['branded'].describe() print '\nGENERIC\n' print df['generic'].describe() 这将产生: BRANDED count 5158 unique 182 top 1 freq 334 Name: branded, dtype:

为什么熊猫会在两个类型均为
float64
的列上为
descripe()
打印不同类型的输出

我的密码是:

print '\nBRANDED\n'
print df['branded'].describe()
print '\nGENERIC\n'
print df['generic'].describe()
这将产生:

BRANDED

count     5158
unique     182
top          1
freq       334
Name: branded, dtype: float64

GENERIC

count     7955.000000
mean      5465.802137
std       4028.148729
min          1.000000
25%       2617.000000
50%       4523.000000
75%       7264.000000
max      42788.000000
Name: generic, dtype: float64
如果两列的类型都是
float64
,那么为什么第一列看起来不像是数字

它可能有一些空值,但我不明白为什么会有不同


如果是,如何将列转换为数字?

如果要将列转换为
数字
float64
请使用
astype()


我怀疑您的品牌专栏中混合了数据类型
df.info()
显示了什么?作为一个例子,我测试了所有的float,包括缺少的值,然后是一个混合了float和str的列,然后得到了与youThanks相同的结果。是的,你说得很对,
df.info()
显示了
通用7955非空浮点64
但是
品牌5158非空对象
。查看
branded
它似乎包含一些Python
None
对象。我想我需要将它们转换为0.0吗?
None
将转换为
NaN
我想,你确定它们不是str
'None'
?如果你运行的是pandas版本
0.17.0
或更高版本,请尝试
pd.\u numeric(df['branded'])
这会将错误值转换为
NaN
,或引发错误,否则请尝试
df['b']。转换对象(convert\u numeric=True)
那么
len(df['branded'].convert\u对象(convert\u numeric=True))显示什么?另外,我假设您正在从
convert\u objects
返回赋值,这无法回答OP的问题
df["branded"] = df["branded"].astype("float64")