Skip to Content
利用 Python 进行数据分析:原书第 3 版
book

利用 Python 进行数据分析:原书第 3 版

by Wes McKinney
November 2023
Intermediate to advanced
512 pages
11h 53m
Chinese
China Machine Press
Content preview from 利用 Python 进行数据分析:原书第 3 版
时间序列
|
369
使用 pandas.Grouper 存在一个限制,即必须使用时间作为
Series
DataFrame
的索引。
11.7
移动窗口函数
在移动窗口或指数衰减权重上进行统计或运行其他函数,也是一类常见于时间序列的数
组变换。这对于圆滑噪声数据或不连续数据很有帮助。我将其称为移动窗口函数,尽管
其中还包括没有固定长度窗口的函数(比如指数加权移动均值)。与其他统计函数一样,
移动窗口函数也会自动排除缺失数据。
开始之前,我们加载一些时间序列数据,并将其重采样为工作日频率:
现在导入 rolling 运算符,它与 resample groupby 很像。通过一个 window(表示周
期的数量,见图
11-4
),可以在
Series
DataFrame
上调用它:
11-4:苹果公司股价的 250 日均线
370
|
11
表达式 rolling(250) groupby 很像,但它不是进行分组,而是创建一个可以按照
250
日分组的移动窗口对象。然后,我们就得到了苹果公司股价的
250
日移动窗口。
默认情况下,滚动函数需要窗口中所有的值为非
NA
值,可以修改此行为以解决缺失
数据的问题。特别是,实际上在时间序列开始处,数据量就低于 window 周期数(如
11-5
):
11-5 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Brett Slatkin, 鈴木 駿

Publisher Resources

ISBN: 9787111726722