【问题标题】:ValueError: could not convert string to float: '1,060.00'- astype(float)ValueError:无法将字符串转换为浮点数:'1,060.00'- astype(float)
【发布时间】:2021-06-11 09:36:09
【问题描述】:

如您所见,我正在尝试将字符串转换为浮点数,我在 github 中遇到了这段代码,我想看看它如何与我自己的数据一起工作。但是我在这段代码中遇到了问题,每当我运行它时,都会返回 ValueError:无法将字符串转换为浮点数:'1,060.00'- astype(float)。这段代码有问题吗?

from sklearn.preprocessing import MinMaxScaler

minmax = MinMaxScaler().fit(df.iloc[:, 4:5].astype('float32'))

df_log = minmax.transform(df.iloc[:, 4:5].replace.astype('float32')) 

df_log = pd.DataFrame(df_log)

df_log.head()

this is the data i am using

【问题讨论】:

    标签: python pandas scikit-learn


    【解决方案1】:

    "1,060.00" 不能转换为浮点数,因为里面有逗号。尝试使用 this function 将特定列中的所有逗号替换为“”(空字符串),然后再转换为浮点数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 2018-06-13
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多