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数据处理
44
3
写完上述代码后,保存文件并运行。如你所见,在
Python
中打开
JSON
文件并将其转换成
由字典组成的列表是非常容易的。下一节将探索更多自定义文件的处理方法。
3.3
 
XML
数据
XML
格式的数据既便于机器读取,也便于人工读取。但是对于本章的数据集来说,预
览并理解
CSV
文件和
JSON
文件要比
XML
文件容易得多。幸运的是,数据本身是相同
的,我们也比较熟悉。下载预期寿命数据的
XML
版本(下载地址:
http://apps.who.int/gho/
athena/data/GHO/WHOSIS_000001,WHOSIS_000002.xml?filter=COUNTRY:*;YEAR:2015
),
并将
XML
文件与本章其他内容保存在同一文件夹下。
如果文件的扩展名是
.xml
,那么它是
XML
数据。如果文件扩展名是
.html
.xhtml
,有时也可以用
XML
解析器来解析。
在处理所有数据时,我们先在代码编辑器中打开文件来预览一下。如果你滚动查看一下文
件,会发现我们在
CSV
的例子中已经熟悉的数据。但数据看起来又不大一样,因为它用
的是
XML
格式,使用了一种叫作
标签
的东西。
XML
是一种标记语言,也就是说,它具有包含格式化数据的文档结构。
XML
文档本质上只是格式特殊的数据文件。
下面的数据片段是我们要处理的
XML
数据的一个样本。在这个例子中,
<Observation />
<Dim />
<Display />
都是标签。标签(或节点)以层次化和结构化的方式保存数据:
<
GHO
...>
<
Data ...
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