问题描述
如您所见,我正在尝试将字符串转换为浮点数,我在 github 中遇到了这段代码,我想看看它与我自己的数据的配合情况。但是我在这段代码中遇到了问题,每当我运行它时,都会返回 ValueError: Could not convert string to float: '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()
解决方法
“1,060.00”无法转换为浮点数,因为那里有逗号。在转换为浮动之前,尝试使用 this function 将特定列中的所有逗号替换为 ""(空字符串)。