Skip to Content
Python数据处理
book

Python数据处理

by Jacqueline Kazil, Katharine Jarmul
July 2017
Intermediate to advanced
398 pages
11h 54m
Chinese
Posts & Telecom Press
Content preview from Python数据处理
150
7
读更多正则表达式的内容,我们推荐在
RegExr
网站(
http://www.regexr.com/
)上试用交互
式正则表达式解析器,还可以通读免费的正则表达式教程(
http://www.regular-expressions.
info/tutorial.html
)。
前面学过了这么多匹配方法,现在你可以轻松找出重复值。下面我们来看一下,在我们的
数据集中遇到重复值时可以有哪些做法。
7.2.7
 如何处理重复记录
根据你的数据状态,你可能希望合并重复记录。如果你的数据集只有重复行,那就无需担
心数据存储的问题,这些数据已经包含在最终数据集内,你只需在清洗后的数据中删除或
舍弃这些行即可。但如果你要合并不同的数据集,并希望保存每一条重复数据,那你需要
思考用
Python
实现的最佳做法。
在第
9
章我们将会讲到合并数据的一般性方法,用到一些新库。但合并数据行还有简单的
方法,和你解析数据的方法相同。如果你用
DictReader
提取数据的话,我们用一个例子
来讲解这个方法。我们将合并男性数据集的一些数据行。这次我们希望基于家庭来合并数
据,所以我们关注的是每一家的调查,而不是每个人的调查:
from
csv
import
DictReader
mn_data_rdr = DictReader(open('data/unicef/mn.csv', 'rb'))
mn_data = [d
for
d
in
mn_data_rdr]
def
combine_data_dict(data_rows): ...
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

数据科学中的实用统计学(第2版)

数据科学中的实用统计学(第2版)

Peter Bruce, Andrew Bruce, Peter Gedeck
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115459190