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 版
时间序列
|
353
简单型和时区型的对象间不支持运算,如果运算将会抛出异常。
11.5
周期及其算术运算
周期表示的是时间段,比如数日、数月、数季、数年等。pandas.Period 类所表示的就
是这种数据类型,它需要用到字符串或整数,以及表
11-4
中的频率:
在这个例子中,Period 对象表示的是从
2011
1
1
日到
2011
12
31
日之间的整
段时间。只需对周期对象加上或减去一个整数,就可以移动其频率:
如果两个周期对象拥有相同的频率,则二者的差就是它们之间日期偏移量的单位数量:
period_range 函数可用于创建规则的周期范围:
354
|
11
PeriodIndex 类保存了一组周期序列,它可以在任何
pandas
数据结构中用作轴索引:
如果你有一个字符串数组,也可以使用 PeriodIndex 类(所有值均为周期对象):
11.5.1
周期的频率转换
周期和 PeriodIndex 对象都可以通过其 asfreq 方法转换为别的频率。举个例子,假
设我们有一个年度周期,希望将其转换为当年年初或年末的一个月度周期,可以如下
实现:
可以将 Period('2011','A-DEC') 看作一个时间段中的游标,该时间段被划分为多个月
度周期。图
11-1
对此进行了说明。对于不是以十二月作为结束月的财政年度,相应的月 ...
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