我有以下功能:
$_GET
然而,我收到错误:
def windows(files):
x = []
for my_files in files:
df = pd.DataFrame(columns=['timestamp', 'time skipped', 'x', 'y', 'z', 'label']).set_index('timestamp')
with open(os.path.join("/Users", "saqibali", "PycharmProjects", "sensorLogProject", "Data", my_files),
'rU') as my_file:
for d in sliding_window(sample_difference(my_file), 50, 25):
df = df.append(d)
x.append(df[['x', 'y', 'z']].values.tolist())
return x
def principal_components():
pca = PCA(n_components=2)
training_result = pca.fit_transform(windows(training_files))
testing_result = pca.transform(windows(test_files))
return training_result, testing_result
追溯是:
ValueError: setting an array element with a sequence.
以下是/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/saqibali/PycharmProjects/sensorLogProject/FeatureSelection/FeatureSelection.py
Traceback (most recent call last):
File "/Users/saqibali/PycharmProjects/sensorLogProject/FeatureSelection/FeatureSelection.py", line 61, in <module>
principal_components()
File "/Users/saqibali/PycharmProjects/sensorLogProject/FeatureSelection/FeatureSelection.py", line 56, in principal_components
training_result = pca.fit_transform(windows(training_files))
File "/Users/saqibali/Library/Python/2.7/lib/python/site-packages/sklearn/decomposition/pca.py", line 324, in fit_transform
U, S, V = self._fit(X)
File "/Users/saqibali/Library/Python/2.7/lib/python/site-packages/sklearn/decomposition/pca.py", line 346, in _fit
copy=self.copy)
File "/Users/saqibali/Library/Python/2.7/lib/python/site-packages/sklearn/utils/validation.py", line 382, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
的例子:
df
根据下面的评论,我在以下函数中使用 time skipped x y z \
timestamp
1970-01-01 00:00:01.501514704 0 -0.055908 -0.729034 -0.645294
1970-01-01 00:00:01.501514704 0 -0.046158 -0.709091 -0.650177
1970-01-01 00:00:01.501514704 0 -0.036469 -0.699554 -0.672668
1970-01-01 00:00:01.501514704 0 -0.027908 -0.695740 -0.678070
1970-01-01 00:00:01.501514704 0 -0.027725 -0.678802 -0.697052
1970-01-01 00:00:01.501514704 0 -0.037491 -0.660660 -0.719605
:
pd.readcsv()
我希望有一个np数组,每个元素都是来自每个单独文件的数据帧的np数组版本。例如,我有一个文件和一个数据框来表示它。我想将其转换为np数组,并将其作为自己的元素添加到最终的np数组中。然后,我会为每个文件做同样的事情。我怎么能这样做?