[英]Pandas treating a float column as non-numeric?
Why does Pandas print different types of output for describe()
on two columns that are both of type float64
? 为什么Pandas在均为float64
类型的两列上为describe()
打印不同类型的输出?
My codes is: 我的代码是:
print '\nBRANDED\n'
print df['branded'].describe()
print '\nGENERIC\n'
print df['generic'].describe()
This outputs: 输出:
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
If both columns are of type float64
, then why does the first column not look like it is numeric? 如果两列都是float64
类型,那么为什么第一列看起来不像数字呢?
It probably has some nulls in it, but I don't understand why that should make a difference. 它可能有一些空值,但是我不明白为什么这应该有所作为。
If it does, how do I convert the column to be numeric? 如果可以,如何将列转换为数字?
如果要将列转换为numeric
列或float64
使用astype()
df["branded"] = df["branded"].astype("float64")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.