我是Python編程的新手。當我嘗試爲主要組件分析標準化數據時,出現以下錯誤消息。ValueError:無效文字爲float():2017-03-18 19:22:51-07:00
Python版本:2.7.4。
df = pd.read_csv('E:/Downloads/Datasets/PCA_data.csv')
df.head()
number_people date timestamp day_of_week \
0 37 2015-08-14 17:00:11-07:00 61211 4
1 45 2015-08-14 17:20:14-07:00 62414 4
2 40 2015-08-14 17:30:15-07:00 63015 4
3 44 2015-08-14 17:40:16-07:00 63616 4
4 45 2015-08-14 17:50:17-07:00 64217 4
is_weekend is_holiday temperature is_start_of_semester \
0 0 0 71.76 0
1 0 0 71.76 0
2 0 0 71.76 0
3 0 0 71.76 0
4 0 0 71.76 0
is_during_semester month hour
0 0 8 17
1 0 8 17
2 0 8 17
3 0 8 17
4 0 8 17
x = df.iloc[:,1:8] # all rows, all the features and no labels
y = df.iloc[:, 0] # all rows, label only
# Scale the data to be between -1 and 1
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X = scaler.fit_transform(x)
X
X = scaler.fit_transform(x)
Traceback (most recent call last):
File "<ipython-input-28-ce4e52c57a0a>", line 1, in <module>
X = scaler.fit_transform(x)
File "C:\Users\owner\Anaconda2\lib\site-packages\sklearn\base.py", line 494, in fit_transform
return self.fit(X, **fit_params).transform(X)
File "C:\Users\owner\Anaconda2\lib\site-packages\sklearn\preprocessing\data.py", line 560, in fit
return self.partial_fit(X, y)
File "C:\Users\owner\Anaconda2\lib\site-packages\sklearn\preprocessing\data.py", line 583, in partial_fit
estimator=self, dtype=FLOAT_DTYPES)
File "C:\Users\owner\Anaconda2\lib\site-packages\sklearn\utils\validation.py", line 382, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: invalid literal for float(): 2017-03-18 19:22:51-07:00
請有人看看它..很多預先感謝。
你有一個日期列在那裏。你想用它做什麼? –
謝謝..我要刪除'日期'和'時間戳'專欄.. –