Skip to Content
Java数据科学实战
book

Java数据科学实战

by Michael R. Brzustowicz, PhD
January 2020
Intermediate to advanced
202 pages
5h 41m
Chinese
Posts & Telecom Press
Content preview from Java数据科学实战
数据的输入与输出
|
7
行时进行解析,仅保留那些需要的值,并把这些记录填充到数据结构中。如果每行有
1000
个变量,而只需要其中的
3
个,则没必要保存所有变量。同样,若某一行中的数据不符合
某个标准,则也没有必要保存该行。对于大型数据集,相比于把所有行读入到字符串数组
(
String[]
)中,随后再进行解析,这种方法可以节省很多资源。在管理数据文件的这一
步骤中,考虑得越多,收获就越大。不论是统计、学习还是绘制,这些后续的每个步骤都
将依赖于构建数据集时的决策。俗话说“输入的是无用数据,那么输出的也一定是无用数
据”,这绝对在理。
1.4.1
 首先理解文件内容
数据文件的结构繁杂,可能会呈现一些不符合需要的
特征
(
feature
)。回忆一下,
ASCII
文
件仅是打印到每一行上的一些
ASCII
字符的集合。它无法保证数值的格式或精度,也不能
保证是采用单引号还是双引号,以及是否包含大量空格、空值以及换行符。简而言之,不
管对文件内容做了怎样的假设,文件每一行所包含的内容都可能是各式各样的。用
Java
读
取文件之前,先用文本编辑器或命令行看一下该文件。注意每一行中每一项的个数、位置
以及类型,要特别关注缺失的值或空值是如何表示的。同样,要注意分隔符的类型,以及
任何描述数据的头部。若文件足够小,则可以通过肉眼来查看哪些行有缺失或格式错误。
例如,假定在
bash shell
中采用
UNIX
命令
less
来查看
somefile.txt
文件:
bash$
less
somefile.txt
"id","year","city" ...
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

云安全实用指南

云安全实用指南

Chris Dotson
Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino

Publisher Resources

ISBN: 9787115533302