西比傅里叶变换键错误:"对齐"?



我正试图在我拥有的pandas数据框架上运行快速傅里叶变换。我用的是开普勒系外行星数据集,这里,还有一个专门的笔记本,这里。我重新创建单元格27-30中的代码(注意,单元格29中的代码在其他地方执行,因此两个数据框具有与原始笔记本相同的形状),如下所示:

import scipy
def spectrum_getter(X):
Spectrum = scipy.fft.fft(X, n=X.size)
return np.abs(Spectrum)
x_train_OS_FT = x_train_OS.apply(spectrum_getter, axis=1)
x_test_FT = x_test.apply(spectrum_getter, axis=1)

x_train_OS和x_test都是pandas.core.frame.DataFrame。运行该命令产生:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [245], in <module>
----> 1 x_train_OS_FT = x_train_OS.apply(spectrum_getter, axis=1)
2 x_test_FT = x_test.apply(spectrum_getter, axis=1)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagespandascoreframe.py:8827, in DataFrame.apply(self, func, axis, raw, result_type, args, **kwargs)
8816 from pandas.core.apply import frame_apply
8818 op = frame_apply(
8819     self,
8820     func=func,
(...)
8825     kwargs=kwargs,
8826 )
-> 8827 return op.apply().__finalize__(self, method="apply")
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagespandascoreapply.py:727, in FrameApply.apply(self)
724 elif self.raw:
725     return self.apply_raw()
--> 727 return self.apply_standard()
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagespandascoreapply.py:851, in FrameApply.apply_standard(self)
850 def apply_standard(self):
--> 851     results, res_index = self.apply_series_generator()
853     # wrap results
854     return self.wrap_results(results, res_index)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagespandascoreapply.py:867, in FrameApply.apply_series_generator(self)
864 with option_context("mode.chained_assignment", None):
865     for i, v in enumerate(series_gen):
866         # ignore SettingWithCopy here in case the user mutates
--> 867         results[i] = self.f(v)
868         if isinstance(results[i], ABCSeries):
869             # If we have a view on v, we need to make a copy because
870             #  series_generator will swap out the underlying data
871             results[i] = results[i].copy(deep=False)
Input In [244], in spectrum_getter(X)
3 def spectrum_getter(X):
----> 4     Spectrum = scipy.fft.fft(X, n=X.size)
5     return np.abs(Spectrum)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesscipyfft_backend.py:22, in _ScipyBackend.__ua_function__(method, args, kwargs)
20 if fn is None:
21     return NotImplemented
---> 22 return fn(*args, **kwargs)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesscipyfft_pocketfftbasic.py:17, in c2c(forward, x, n, axis, norm, overwrite_x, workers, plan)
14 if plan is not None:
15     raise NotImplementedError('Passing a precomputed plan is not yet '
16                               'supported by scipy.fft functions')
---> 17 tmp = _asfarray(x)
18 overwrite_x = overwrite_x or _datacopied(tmp, x)
19 norm = _normalization(norm, forward)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesscipyfft_pocketffthelper.py:97, in _asfarray(x)
95 dtype = x.dtype.newbyteorder('=')
96 # Always align input
---> 97 copy = not x.flags['ALIGNED']
98 return np.array(x, dtype=dtype, copy=copy)
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagespandascoreflags.py:98, in Flags.__getitem__(self, key)
96 def __getitem__(self, key):
97     if key not in self._keys:
---> 98         raise KeyError(key)
100     return getattr(self, key)
KeyError: 'ALIGNED'

我试图将数据帧转换为numpy数组,但遇到了其他问题。我哪里做错了?

我运行到相同的错误,所以我把我的数据类型转换为数据帧,它解决了我的问题。

最新更新