热线电话:13121318867

登录
2019-03-04 阅读量: 667
为什么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,但是无法应用函数。请指教。

解决办法:因为apply将它接收的函数作为参数接收,并使用该系列的每个元素调用它。

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

0.0000
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子