小编Bra*_*ide的帖子

将pandas Dataframe转换为float

我无法将数据框中的数据类型转换为从字符串浮点型(它们是字符串或空字符串形式的数值):

calcMeanPrice_df = dessertApples_df.iloc[:, 5:17]      #slice of columns

for col  in calcMeanPrice_df:                          #iterate columns
    pd.to_numeric(col, errors = 'coerce')              #attempt to convert to numeric

calcMeanPrice_df.dtypes                                #return data column types

Out[21]:
4     object
5     object
6     object
7     object
8     object
9     object
10    object
11    object
12    object
13    object
14    object
15    object
dtype: object
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

python dataframe python-3.x pandas

2
推荐指数
1
解决办法
3320
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1

python-3.x ×1