为什么不能随滚动应用INT64类型



我有此数据:

                    Date        Time        Last    Volume
2019-03-01 20:36:00 2019-03-01  20:36:00    11626   94
2019-03-01 20:39:00 2019-03-01  20:39:00    11629   102
2019-03-01 20:42:00 2019-03-01  20:42:00    11631   151
2019-03-01 20:45:00 2019-03-01  20:45:00    11630   141
2019-03-01 20:48:00 2019-03-01  20:48:00    11629   100
2019-03-01 20:51:00 2019-03-01  20:51:00    11628   77
2019-03-01 20:54:00 2019-03-01  20:54:00    11627   165
2019-03-01 20:57:00 2019-03-01  20:57:00    11633   265
2019-03-01 21:00:00 2019-03-01  21:00:00    11633   1
2019-03-01 21:03:00 2019-03-01  21:03:00    11629   19

它是从CVS文件中导入的然后我使用以下方式转换值:

data['Last']=data['Last'].astype(np.int64)
data['Volume']=data['Volume'].astype(np.int64) 

data.info()是:

> <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 160104 entries,
> 2017-01-02 07:00:00 to 2019-03-01 21:03:00 Data columns (total 4
> columns): Date      160104 non-null datetime64[ns] Time      160104
> non-null object Last      160104 non-null int64 Volume    160104
> non-null int64 dtypes: datetime64[ns](1), int64(2), object(1)

尝试创建这样的lambda函数时:

outcomes = pd.DataFrame(index=data.index)
ma_5 = lambda x: x.rolling(5).mean()
outcomes['f06'] = data.Volume.apply(ma_5).apply(np.log) 

我遇到了一个错误:

AttributeError: 'int' object has no attribute 'rolling'

因此,尽管我确实将Float转换为INT64,但无法应用功能。请建议。

,因为应用将其作为参数接收到的函数称为该系列的每个元素。

您只是在寻找outcomes['f06'] = data.Volume.rolling(5).mean().apply(np.log)

最新更新