为什么我的代码中出现字符串浮动错误?

时间:2019-09-09 14:33:47

标签: python keras neural-network

我收到“无法将字符串转换为浮点:'\ ufeffage'”错误,我不知道为什么

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense
from tensorflow.python.keras.wrappers.scikit_learn import KerasRegressor
import os;

path = pd.read_csv('car.csv')

path.replace(",",".")

dataset=np.loadtxt("car.csv", delimiter=",")
x=dataset[:,0:5]
y=dataset[:,5]
y=np.reshape(y, (-1,1))
scaler = MinMaxScaler()
print(scaler.fit(x))
print(scaler.fit(y))
xscale=scaler.transform(x)
yscale=scaler.transform(y)

最后一部分是发生错误的地方

1 个答案:

答案 0 :(得分:0)

您正在读取的文件包含字节顺序标记和列名称。熊猫read_csv会自动处理此问题,但np.loadtext不会。将脚本的前三行更改为此应该会有所帮助:

dataset=pd.read_csv('car.csv').values