简体   繁体   中英

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 ?

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?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM