100% found this document useful (5 votes)
501 views

Learning pandas Python Data Discovery and Analysis Made Easy Heydt Michael download pdf

Made

Uploaded by

dezongla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
501 views

Learning pandas Python Data Discovery and Analysis Made Easy Heydt Michael download pdf

Made

Uploaded by

dezongla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebookmeta.

com

Learning pandas Python Data Discovery and Analysis


Made Easy Heydt Michael

https://ebookmeta.com/product/learning-pandas-python-data-
discovery-and-analysis-made-easy-heydt-michael/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Python Data Analysis Numpy, Matplotlib and Pandas Bernd


Klein

https://ebookmeta.com/product/python-data-analysis-numpy-matplotlib-
and-pandas-bernd-klein/

ebookmeta.com

Python Data Analytics Data Analysis and Science Using


Pandas Matplotlib and the Python Programming Language 1st
Edition Nelli Fabio
https://ebookmeta.com/product/python-data-analytics-data-analysis-and-
science-using-pandas-matplotlib-and-the-python-programming-
language-1st-edition-nelli-fabio/
ebookmeta.com

Python Data Analytics Data Analysis and Science Using


Pandas Matplotlib and the Python Programming Language 1st
Edition Nelli Fabio
https://ebookmeta.com/product/python-data-analytics-data-analysis-and-
science-using-pandas-matplotlib-and-the-python-programming-
language-1st-edition-nelli-fabio-2/
ebookmeta.com

Wild Irish Wild Noble Kindle Worlds Novella 1st Edition


Shyla Colt [Colt

https://ebookmeta.com/product/wild-irish-wild-noble-kindle-worlds-
novella-1st-edition-shyla-colt-colt/

ebookmeta.com
Statistics with Julia: Fundamentals for Data Science,
Machine Learning and Artificial Intelligence 1st Edition
Yoni Nazarathy
https://ebookmeta.com/product/statistics-with-julia-fundamentals-for-
data-science-machine-learning-and-artificial-intelligence-1st-edition-
yoni-nazarathy-2/
ebookmeta.com

Leelyn Curvy Woman Country Boy Romance Love in the Falls


Book 1 1st Edition Ally Crew & Brynn Hale [Crew

https://ebookmeta.com/product/leelyn-curvy-woman-country-boy-romance-
love-in-the-falls-book-1-1st-edition-ally-crew-brynn-hale-crew/

ebookmeta.com

Lithuanian A Comprehensive Grammar 1st Edition Meilut■


Ramonien■ Joana Pribušauskait■ Jogil■ Teresa Ramonait■
Loreta Vilkien■
https://ebookmeta.com/product/lithuanian-a-comprehensive-grammar-1st-
edition-meilute-ramoniene-joana-pribusauskaite-jogile-teresa-
ramonaite-loreta-vilkiene/
ebookmeta.com

Breaking Barriers A History of Integration in Professional


Basketball 1st Edition Douglas Stark

https://ebookmeta.com/product/breaking-barriers-a-history-of-
integration-in-professional-basketball-1st-edition-douglas-stark/

ebookmeta.com

The Moral Heart of Public Service 1st Edition Claire


Foster-Gilbert

https://ebookmeta.com/product/the-moral-heart-of-public-service-1st-
edition-claire-foster-gilbert/

ebookmeta.com
The Chernobyl Fukushima Daiichi And Deepwater Horizon
Disasters From A Natural Science And Humanities
Perspective 1st Edition Volker Hoensch
https://ebookmeta.com/product/the-chernobyl-fukushima-daiichi-and-
deepwater-horizon-disasters-from-a-natural-science-and-humanities-
perspective-1st-edition-volker-hoensch/
ebookmeta.com
[1]
Learning pandas

Get to grips with pandas—a versatile


and high-performance Python library for
data manipulation, analysis, and discovery

Michael Heydt

BIRMINGHAM - MUMBAI
Learning pandas

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: April 2015

Production reference: 1090415

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78398-512-8

www.packtpub.com
Credits

Author Project Coordinator


Michael Heydt Mary Alex

Reviewers Proofreaders
Bill Chambers Simran Bhogal
S. Shelly Jang Paul Hindle
Arun Karunagath Rajeevan Linda Morris
Daniel Velkov Christopher Smith
Adrian Wan
Indexer
Commissioning Editor Monica Ajmera Mehta
Kartikey Pandey
Graphics
Acquisition Editor Sheetal Aute
Neha Nagwekar
Production Coordinator
Content Development Editor Arvindkumar Gupta
Akshay Nair
Cover Work
Technical Editors Arvindkumar Gupta
Shashank Desai
Chinmay Puranik

Copy Editors
Roshni Banerjee
Pranjali Chury
Stuti Srivastava
About the Author

Michael Heydt is an independent consultant, educator, and trainer with nearly


30 years of professional software development experience, during which he focused
on agile software design and implementation using advanced technologies in
multiple verticals, including media, finance, energy, and healthcare. He holds an MS
degree in mathematics and computer science from Drexel University and an executive
master's of technology management degree from the University of Pennsylvania's
School of Engineering and Wharton Business School. His studies and research
have focused on technology management, software engineering, entrepreneurship,
information retrieval, data sciences, and computational finance. Since 2005, he
has been specializing in building energy and financial trading systems for major
investment banks on Wall Street and for several global energy trading companies,
utilizing .NET, C#, WPF, TPL, DataFlow, Python, R, Mono, iOS, and Android. His
current interests include creating seamless applications using desktop, mobile, and
wearable technologies, which utilize high concurrency, high availability, real-time
data analytics, augmented and virtual reality, cloud services, messaging, computer
vision, natural user interfaces, and software-defined networks. He is the author of
numerous technology articles, papers, and books (Instant Lucene.NET, Learning
pandas). He is a frequent speaker at .NET users' groups and various mobile and cloud
conferences, and he regularly delivers webinars on advanced technologies.
About the Reviewers

Bill Chambers is a Python developer and data scientist currently pursuing a


master of information management and systems degree at the UC Berkeley School
of Information. Previously, he focused on data architecture and systems using
marketing, sales, and customer analytics data. Bill is passionate about delivering
actionable insights and innovative solutions using data.

You can find more information about him at http://www.billchambers.me.

S. Shelly Jang received her PhD degree in electrical engineering from the
University of Washington and a master's degree in chemical and biological
engineering from the University of British Columbia in 2014 and 2009, respectively.
She was an Insight Data Science fellow in 2014. During her tenure, she built a
web app that recommends crowd-verified treatment options for various medical
conditions. She is currently a senior data scientist at AT&T Big Data. Exploring
complex, large-scale data sets to build models and derive insights is just a part
of her job.

In her free time, she participates in the Quantified Self community, sharing her
insights on personal analytics and self-hacking.

Arun Karunagath Rajeevan is a senior consultant (products) in an exciting


start-up, working as an architect and coder, and is a polyglot. He is currently
involved in developing the best quality management suite in the supply chain
management category.

Apart from this, he has experience in healthcare and multimedia (embedded)


domains. When he is not working, he loves to travel and listen to music.
Daniel Velkov is a software engineer based in San Francisco, who has more than
10 years of programming experience. His biggest professional accomplishment
was designing and implementing the search stack for MyLife.com—one of the
major social websites in the US. Nowadays, he works on making Google search
better. Besides Python and search, he has worked on several machine learning and
data analysis-oriented projects. When he is not coding, he enjoys skiing, riding
motorcycles, and exploring the Californian outdoors.

Adrian Wan is a physics and computer science major at Swarthmore College. After
he graduates, he will be working at Nest, a Google company, as a software engineer
and data scientist. His passion lies at the intersection of his two disciplines, where
elegant mathematical models and explanations of real-life phenomena are brought to
life and probed deeply with efficient, clean, and powerful code. He greatly enjoyed
contributing to this book and hopes that you will be able to appreciate the power
that pandas brings to Python.

You can find out more about him at http://awan1.github.io.


www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface vii
Chapter 1: A Tour of pandas 1
pandas and why it is important 2
pandas and IPython Notebooks 3
Referencing pandas in the application 5
Primary pandas objects 6
The pandas Series object 6
The pandas DataFrame object 11
Loading data from files and the Web 18
Loading CSV data from files 18
Loading data from the Web 22
Simplicity of visualization of pandas data 24
Summary 25
Chapter 2: Installing pandas 27
Getting Anaconda 28
Installing Anaconda 29
Installing Anaconda on Linux 30
Installing Anaconda on Mac OS X 32
Installing Anaconda on Windows 33
Ensuring pandas is up to date 35
Running a small pandas sample in IPython 38
Starting the IPython Notebook server 39
Installing and running IPython Notebooks 43
Using Wakari for pandas 45
Summary 47

[i]
Table of Contents

Chapter 3: NumPy for pandas 49


Installing and importing NumPy 50
Benefits and characteristics of NumPy arrays 50
Creating NumPy arrays and performing basic array operations 52
Selecting array elements 58
Logical operations on arrays 59
Slicing arrays 61
Reshaping arrays 65
Combining arrays 70
Splitting arrays 73
Useful numerical methods of NumPy arrays 79
Summary 82
Chapter 4: The pandas Series Object 83
The Series object 84
Importing pandas 85
Creating Series 85
Size, shape, uniqueness, and counts of values 91
Peeking at data with heads, tails, and take 93
Looking up values in Series 95
Alignment via index labels 100
Arithmetic operations 102
The special case of Not-A-Number (NaN) 106
Boolean selection 107
Reindexing a Series 110
Modifying a Series in-place 117
Slicing a Series 119
Summary 126
Chapter 5: The pandas DataFrame Object 127
Creating DataFrame from scratch 128
Example data 132
S&P 500 133
Monthly stock historical prices 135
Selecting columns of a DataFrame 136
Selecting rows and values of a DataFrame using the index 142
Slicing using the [] operator 142
Selecting rows by index label and location: .loc[] and .iloc[] 143
Selecting rows by index label and/or location: .ix[] 145
Scalar lookup by label or location using .at[] and .iat[] 146
Selecting rows of a DataFrame by Boolean selection 146

[ ii ]
Table of Contents

Modifying the structure and content of DataFrame 148


Renaming columns 148
Adding and inserting columns 150
Replacing the contents of a column 153
Deleting columns in a DataFrame 154
Adding rows to a DataFrame 157
Appending rows with .append() 157
Concatenating DataFrame objects with pd.concat() 159
Adding rows (and columns) via setting with enlargement 165
Removing rows from a DataFrame 166
Removing rows using .drop() 166
Removing rows using Boolean selection 168
Removing rows using a slice 169
Changing scalar values in a DataFrame 170
Arithmetic on a DataFrame 172
Resetting and reindexing 176
Hierarchical indexing 179
Summarized data and descriptive statistics 185
Summary 191
Chapter 6: Accessing Data 193
Setting up the IPython notebook 194
CSV and Text/Tabular format 194
The sample CSV data set 194
Reading a CSV file into a DataFrame 195
Specifying the index column when reading a CSV file 196
Data type inference and specification 196
Specifying column names 197
Specifying specific columns to load 198
Saving DataFrame to a CSV file 199
General field-delimited data 200
Handling noise rows in field-delimited data 201
Reading and writing data in an Excel format 204
Reading and writing JSON files 207
Reading HTML data from the Web 208
Reading and writing HDF5 format files 211
Accessing data on the web and in the cloud 213
Reading and writing from/to SQL databases 214
Reading data from remote data services 217
Reading stock data from Yahoo! and Google Finance 218
Retrieving data from Yahoo! Finance Options 219
Reading economic data from the Federal Reserve Bank of St. Louis 222
Accessing Kenneth French's data 225
Reading from the World Bank 226
Summary 234
[ iii ]
Table of Contents

Chapter 7: Tidying Up Your Data 235


What is tidying your data? 236
Setting up the IPython notebook 237
Working with missing data 237
Determining NaN values in Series and DataFrame objects 239
Selecting out or dropping missing data 241
How pandas handles NaN values in mathematical operations 246
Filling in missing data 248
Forward and backward filling of missing values 250
Filling using index labels 251
Interpolation of missing values 252
Handling duplicate data 255
Transforming Data 259
Mapping 259
Replacing values 261
Applying functions to transform data 264
Summary 269
Chapter 8: Combining and Reshaping Data 271
Setting up the IPython notebook 272
Concatenating data 272
Merging and joining data 281
An overview of merges 281
Specifying the join semantics of a merge operation 286
Pivoting 289
Stacking and unstacking 290
Stacking using nonhierarchical indexes 291
Unstacking using hierarchical indexes 293
Melting 298
Performance benefits of stacked data 299
Summary 300
Chapter 9: Grouping and Aggregating Data 303
Setting up the IPython notebook 304
The split, apply, and combine (SAC) pattern 304
Split 306
Data for the examples 306
Grouping by a single column's values 307
Accessing the results of grouping 308
Grouping using index levels 314
Apply 318
Applying aggregation functions to groups 318

[ iv ]
Table of Contents

The transformation of group data 322


An overview of transformation 322
Practical examples of transformation 326
Filtering groups 333
Discretization and Binning 335
Summary 341
Chapter 10: Time-series Data 343
Setting up the IPython notebook 344
Representation of dates, time, and intervals 345
The datetime, day, and time objects 345
Timestamp objects 347
Timedelta 349
Introducing time-series data 350
DatetimeIndex 350
Creating time-series data with specific frequencies 357
Calculating new dates using offsets 359
Date offsets 360
Anchored offsets 364
Representing durations of time using Period objects 366
The Period object 366
PeriodIndex 368
Handling holidays using calendars 372
Normalizing timestamps using time zones 373
Manipulating time-series data 379
Shifting and lagging 379
Frequency conversion 383
Up and down resampling 386
Time-series moving-window operations 391
Summary 395
Chapter 11: Visualization 397
Setting up the IPython notebook 398
Plotting basics with pandas 399
Creating time-series charts with .plot() 400
Adorning and styling your time-series plot 404
Adding a title and changing axes labels 404
Specifying the legend content and position 406
Specifying line colors, styles, thickness, and markers 408
Specifying tick mark locations and tick labels 412
Formatting axes tick date labels using formatters 415
Common plots used in statistical analyses 421
Bar plots 422

[v]
Table of Contents

Histograms 424
Box and whisker charts 427
Area plots 428
Scatter plots 430
Density plot 432
The scatter plot matrix 433
Heatmaps 435
Multiple plots in a single chart 436
Summary 440
Chapter 12: Applications to Finance 441
Setting up the IPython notebook 442
Obtaining and organizing stock data from Yahoo! 442
Plotting time-series prices 447
Plotting volume-series data 449
Calculating the simple daily percentage change 451
Calculating simple daily cumulative returns 453
Resampling data from daily to monthly returns 455
Analyzing distribution of returns 457
Performing a moving-average calculation 460
The comparison of average daily returns across stocks 461
The correlation of stocks based on the daily percentage
change of the closing price 465
Volatility calculation 467
Determining risk relative to expected returns 468
Summary 471
Index 473

[ vi ]
Preface
This book is about learning to use pandas, an open source library for Python, which
was created to enable Python to easily manipulate and perform powerful statistical
and mathematical analyses on tabular and multidimensional datasets. The design of
pandas and its power combined with the familiarity of Python have created explosive
growth in its usage over the last several years, particularly among financial firms as
well as those simply looking for practical tools for statistical and data analysis.

While there exist many excellent examples of using pandas to solve many
domain-specific problems, it can be difficult to find a cohesive set of examples
in a form that allows one to effectively learn and apply the features of pandas.
The information required to learn practical skills in using pandas is distributed
across many websites, slide shares, and videos, and is generally not in a form
that gives an integrated guide to all of the features with practical examples in
an easy-to-understand and applicable fashion.

This book is therefore intended to be a go-to reference for learning pandas. It will
take you all the way from installation, through to creating one- and two-dimensional
indexed data structures, to grouping data and slicing-and-dicing them, with common
analyses used to demonstrate derivation of useful results. This will include the
loading and saving of data from resources that are local and Internet-based and
creating effective data visualizations that provide instant ability to visually realize
insights into the meaning previously hidden within complex data.

What this book covers


Chapter 1, A Tour of pandas, is a hands-on introduction to the key features of pandas.
It will give you a broad overview of the types of data tasks that can be performed
with pandas. This chapter will set the groundwork for learning as all concepts
introduced in this chapter will be expanded upon in subsequent chapters.

[ vii ]
Preface

Chapter 2, Installing pandas, will show you how to install Anaconda Python and pandas
on Windows, OS X, and Linux. This chapter also covers using the conda package
manager to upgrade pandas and its dependent libraries to the most recent version.

Chapter 3, NumPy for pandas, will introduce you to concepts in NumPy,


particularly NumPy arrays, which are core for understanding the pandas
Series and DataFrame objects.

Chapter 4, The pandas Series Object, covers the pandas Series object and how it
expands upon the functionality of the NumPy array to provide richer representation
and manipulation of sequences of data through the use of high-performance indexes.

Chapter 5, The pandas DataFrame Object, introduces the primary data structure of
pandas, the DataFrame object, and how it forms a two-dimensional representation of
tabular data by aligning multiple Series objects along a common index to provide
seamless access and manipulation across elements in multiple series that are related
by a common index label.

Chapter 6, Accessing Data, shows how data can be loaded and saved from external
sources into both Series and DataFrame objects. You will learn how to access
data from multiple sources such as files, HTTP servers, database systems, and
web services, as well as how to process data in CSV, HTML, and JSON formats.

Chapter 7, Tidying Up Your Data, instructs you on how to use the various tools
provided by pandas for managing dirty and missing data.

Chapter 8, Combining and Reshaping Data, covers various techniques for combining,
splitting, joining, and merging data located in multiple pandas objects, and
then demonstrates how to reshape data using concepts such as pivots, stacking,
and melting.

Chapter 9, Grouping and Aggregating Data, focuses on how to use pandas to group data
to enable you to perform aggregate operations on grouped data to assist in deriving
analytic results.

Chapter 10, Time-series Data, will instruct you on how to use pandas to represent
sequences of information that is indexed by the progression of time. This chapter
will first cover how pandas represents dates and time, as well as concepts such as
periods, frequencies, time zones, and calendars. The focus then shifts to time-series
data and various operations such as shifting, lagging, resampling, and moving
window operations.

[ viii ]
Preface

Chapter 11, Visualization, dives into the integration of pandas with matplotlib to
visualize pandas data. This chapter will demonstrate how to represent and present
many common statistical and financial data visualizations, including bar charts,
histograms, scatter plots, area plots, density plots, and heat maps.

Chapter 12, Applications to Finance, brings together everything learned through the
previous chapters with practical examples of using pandas to obtain, manipulate,
analyze, and visualize stock data.

What you need for this book


This book assumes some familiarity with programming concepts, but those
without programming experience, or specifically Python programming experience,
will be comfortable with the examples as they focus on pandas constructs more
than Python or programming. The examples are based on Anaconda Python 2.7
and pandas 0.15.1. If you do not have either installed, guidance will be given in
Chapter 2, Installing pandas, on installing both on Windows, OS X, and Ubuntu
systems. For those not interested in installing any software, instructions are also
given on using the Warkari.io online Python data analysis service.

Who this book is for


If you are looking to get into data science and want to learn how to use the Python
programming language for data analysis instead of other domain-specific data
science tools such as R, then this book is for you. If you have used other data science
packages and want to learn how to apply that knowledge to Python, then this book
is also for you. Alternately, if you want to learn an additional tool or start with data
science to enhance your career, then this book is for you.

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

Code words in text are shown as follows: "This information can be easily imported
into DataFrame using the pd.read_csv() function as follows."

[ ix ]
Preface

Any command-line / IPython input or output is written as follows:


In [1]:
# import numpy and pandas, and DataFrame / Series
import numpy as np
import pandas as pd
from pandas import DataFrame, Series

New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "Clicking
on the New Notebook button will present you with a notebook where you can start
entering your pandas code."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to [email protected],


and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

[x]
Preface

Downloading the example code


You can download the example code files for all Packt books you have purchased
from your account at http://www.packtpub.com. If you purchased this book
elsewhere, you can visit http://www.packtpub.com/support and register to have
the files e-mailed directly to you. The code examples in the book are also publicly
available on Wakari.io at https://wakari.io/sharing/bundle/LearningPandas/
LearningPandas_Index.

Although great efforts are taken to use data that will reproduce
the same output when you execute the samples, there is a
small set of code that uses current data and hence the result of
running those samples may vary from what is published in this
book. These include In [39]: and In [40]: in Chapter 1, A Tour of
pandas, which uses the data of the last three months of Google
stock, as well as a small number of samples used in the later
chapters that demonstrate the usage of date offsets centered on
the current date.

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams
used in this book. The color images will help you better understand the changes in
the output. You can download this file from https://www.packtpub.com/sites/
default/files/downloads/5128OS_ColoredImages.pdf.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books — maybe a mistake in the text or
the code — we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/support, selecting your book, clicking on the errata submission form link, and
entering the details of your errata. Once your errata are verified, your submission will
be accepted and the errata will be uploaded to our website, or added to any list of
existing errata, under the Errata section of that title.

[ xi ]
Preface

Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.

Please contact us at [email protected] with a link to the suspected


pirated material.

We appreciate your help in protecting our authors, and our ability to bring you
valuable content.

Questions
You can contact us at [email protected] if you are having a problem with
any aspect of the book, and we will do our best to address it.

[ xii ]
A Tour of pandas
In this chapter, we will take a look at pandas, which is an open source Python-based
data analysis library. It provides high-performance and easy-to-use data structures
and data analysis tools built with the Python programming language. The pandas
library brings many of the good things from R, specifically the DataFrame objects
and R packages such as plyr and reshape2, and places them in a single library that
you can use in your Python applications.

The development of pandas was begun in 2008 by Wes McKinney when he worked
at AQR Capital Management. It was opened sourced in 2009 and is currently
supported and actively developed by various organizations and contributors. It
was initially designed with finance in mind, specifically with its ability around time
series data manipulation, but emphasizes the data manipulation part of the equation
leaving statistical, financial, and other types of analyses to other Python libraries.

In this chapter, we will take a brief tour of pandas and some of the associated tools
such as IPython notebooks. You will be introduced to a variety of concepts in pandas
for data organization and manipulation in an effort to form both a base understanding
and a frame of reference for deeper coverage in later sections of this book. By the end
of this chapter, you will have a good understanding of the fundamentals of pandas and
even be able to perform basic data manipulations. Also, you will be ready to continue
with later portions of this book for more detailed understanding.

This chapter will introduce you to:

• pandas and why it is important


• IPython and IPython Notebooks
• Referencing pandas in your application
• The Series and DataFrame objects of pandas
• How to load data from files and the Web
• The simplicity of visualizing pandas data
[1]
A Tour of pandas

pandas is always lowercase by convention in pandas documentation,


and this will be a convention followed by this book.

pandas and why it is important


pandas is a library containing high-level data structures and tools that have been
created to assist a Python programmer to perform powerful data manipulations,
and discover information in that data in a simple and fast way.

The simple and effective data analysis requires the ability to index, retrieve,
tidy, reshape, combine, slice, and perform various analyses on both single and
multidimensional data, including heterogeneous typed data that is automatically
aligned along index labels. To enable these capabilities, pandas provides the
following features (and many more not explicitly mentioned here):

• High performance array and table structures for representation of


homogenous and heterogeneous data sets: the Series and DataFrame objects
• Flexible reshaping of data structure, allowing the ability to insert and delete
both rows and columns of tabular data
• Hierarchical indexing of data along multiple axes (both rows and columns),
allowing multiple labels per data item
• Labeling of series and tabular data to facilitate indexing and automatic
alignment of data
• Ability to easily identify and fix missing data, both in floating point and as
non-floating point formats
• Powerful grouping capabilities and a functionality to perform
split-apply-combine operations on series and tabular data
• Simple conversion from ragged and differently indexed data of both NumPy
and Python data structures to pandas objects
• Smart label-based slicing and subsetting of data sets, including intuitive and
flexible merging, and joining of data with SQL-like constructs
• Extensive I/O facilities to load and save data from multiple formats including
CSV, Excel, relational and non-relational databases, HDF5 format, and JSON

[2]
Chapter 1

• Explicit support for time series-specific functionality, providing functionality


for date range generation, moving window statistics, time shifting, lagging,
and so on
• Built-in support to retrieve and automatically parse data from various
web-based data sources such as Yahoo!, Google Finance, the World Bank,
and several others

For those desiring to get into data analysis and the emerging field of data science,
pandas offers an excellent means for a Python programmer (or just an enthusiast)
to learn data manipulation. For those just learning or coming from a statistical
language like R, pandas can offer an excellent introduction to Python as a
programming language.

pandas itself is not a data science toolkit. It does provide some statistical methods
as a matter of convenience, but to draw conclusions from data, it leans upon other
packages in the Python ecosystem, such as SciPy, NumPy, scikit-learn, and upon
graphics libraries such as matplotlib and ggvis for data visualization. This is actually
the strength of pandas over other languages such as R, as pandas applications are
able to leverage an extensive network of robust Python frameworks already built
and tested elsewhere.

In this book, we will look at how to use pandas for data manipulation, with a specific
focus on gathering, cleaning, and manipulation of various forms of data using
pandas. Detailed specifics of data science, finance, econometrics, social network
analysis, Python, and IPython are left as reference. You can refer to some other
excellent books on these topics already available at https://www.packtpub.com/.

pandas and IPython Notebooks


A popular means of using pandas is through the use of IPython Notebooks. IPython
Notebooks provide a web-based interactive computational environment, allowing
the combination of code, text, mathematics, plots, and right media into a web-based
document. IPython Notebooks run in a browser and contain Python code that is run
in a local or server-side Python session that the notebooks communicate with using
WebSockets. Notebooks can also contain markup code and rich media content, and
can be converted to other formats such as PDF, HTML, and slide shows.

[3]
A Tour of pandas

The following is an example of an IPython Notebook from the IPython website


(http://ipython.org/notebook.html) that demonstrates the rich capabilities
of notebooks:

IPython Notebooks are not strictly required for using pandas and can be installed
into your development environment independently or alongside of pandas. During
the course of this this book, we will install pandas and an IPython Notebook server.
You will be able to perform code examples in the text directly in an IPython console
interpreter, and the examples will be packaged as notebooks that can be run with a
local notebook server. Additionally, the workbooks will be available online for easy
and immediate access at https://wakari.io/sharing/bundle/LearningPandas/
LearningPandas_Index.

[4]
Chapter 1

To learn more about IPython Notebooks, visit the notebooks site at


http://ipython.org/ipython-doc/dev/notebook/, and for more
in-depth coverage, refer to another book, Learning IPython for Interactive
Computing and Data Visualization, Cyrille Rossant, Packt Publishing.

Referencing pandas in the application


All pandas programs and examples in this book will always start by importing pandas
(and NumPy) into the Python environment. There is a common convention used in
many publications (web and print) of importing pandas and NumPy, which will also
be used throughout this book. All workbooks and examples for chapters will start with
code similar to the following to initialize the pandas library within Python.
In [1]:
# import numpy and pandas, and DataFrame / Series
import numpy as np
import pandas as pd
from pandas import DataFrame, Series

# Set some pandas options


pd.set_option('display.notebook_repr_html', False)
pd.set_option('display.max_columns', 10)
pd.set_option('display.max_rows', 10)

# And some items for matplotlib


%matplotlib inline
import matplotlib.pyplot as plt
pd.options.display.mpl_style = 'default'

NumPy and pandas go hand-in-hand, as much of pandas is built on NumPy. It


is, therefore, very convenient to import NumPy and put it in a np. namespace.
Likewise, pandas is imported and referenced with a pd. prefix. Since DataFrame
and Series objects of pandas are used so frequently, the third line then imports the
Series and DataFrame objects into the global namespace so that we can use them
without a pd. prefix.

[5]
A Tour of pandas

The three pd.set_options() method calls set up some defaults for IPython
Notebooks and console output from pandas. These specify how wide and high any
output will be, and how many columns it will contain. They can be used to modify
the output of IPython and pandas to fit your personal needs to display results. The
options set here are convenient for formatting the output of the examples to the
constraints of the text.

Primary pandas objects


A programmer of pandas will spend most of their time using two primary objects
provided by the pandas framework: Series and DataFrame. The DataFrame objects
will be the overall workhorse of pandas and the most frequently used as they
provide the means to manipulate tabular and heterogeneous data.

The pandas Series object


The base data structure of pandas is the Series object, which is designed to operate
similar to a NumPy array but also adds index capabilities. A simple way to create a
Series object is by initializing a Series object with a Python array or Python list.

In [2]:
# create a four item DataFrame
s = Series([1, 2, 3, 4])
s

Out [2]:
0 1
1 2
2 3
3 4
dtype: int64

This has created a pandas Series from the list. Notice that printing the series
resulted in what appears to be two columns of data. The first column in the output
is not a column of the Series object, but the index labels. The second column is
the values of the Series object. Each row represents the index label and the value
for that label. This Series was created without specifying an index, so pandas
automatically creates indexes starting at zero and increasing by one.

[6]
Chapter 1

Elements of a Series object can be accessed through the index using []. This informs
the Series which value to return given one or more index values (referred to in
pandas as labels). The following code retrieves the items in the series with labels
1 and 3.

In [3]:
# return a Series with the rows with labels 1 and 3
s[[1, 3]]

Out [3]:
1 2
3 4
dtype: int64

It is important to note that the lookup here is not by zero-based


positions 1 and 3 like an array, but by the values in the index.

A Series object can be created with a user-defined index by specifying the labels for
the index using the index parameter.
In [4]:
# create a series using an explicit index
s = Series([1, 2, 3, 4],
index = ['a', 'b', 'c', 'd'])
s

Out [4]:
a 1
b 2
c 3
d 4
dtype: int64

Notice that the index labels in the output now have the index
values that were specified in the Series constructor.

[7]
A Tour of pandas

Data in the Series object can now be accessed by alphanumeric index labels by
passing a list of the desired labels, as the following demonstrates:
In [5]:
# look up items the series having index 'a' and 'd'
s[['a', 'd']]

Out [5]:
a 1
d 4
dtype: int64

This demonstrates the previous point that the lookup is by label


value and not by zero-based position.

It is still possible to refer to the elements of the Series object by their


numerical position.
In [6]:
# passing a list of integers to a Series that has
# non-integer index labels will look up based upon
# 0-based index like an array
s[[1, 2]]

Out [6]:
b 2
c 3
dtype: int64

A Series is still smart enough to determine that you passed a


list of integers and, therefore, that you want to do value lookup
by zero-based position.

[8]
Chapter 1

The s.index property allows direct access to the index of the Series object.
In [7]:
# get only the index of the Series
s.index

Out [7]:
Index([u'a', u'b', u'c', u'd'], dtype='object')

The index is itself actually a pandas object. This shows us the values of the index and
that the data type of each label in the index is object.

A common usage of a Series in pandas is to represent a time series that associates


date/time index labels with a value. A date range can be created using the pandas
method pd.date_range().
In [8]:
# create a Series who's index is a series of dates
# between the two specified dates (inclusive)
dates = pd.date_range('2014-07-01', '2014-07-06')
dates

Out [8]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-07-01, ..., 2014-07-06]
Length: 6, Freq: D, Timezone: None

This has created a special index in pandas referred to as a


DatetimeIndex, which is a pandas index that is optimized
to index data with dates and times.

At this point, the index is not particularly useful without having values for each
index. We can use this index to create a new Series object with values for each
of the dates.
In [9]:
# create a Series with values (representing temperatures)
# for each date in the index
temps1 = Series([80, 82, 85, 90, 83, 87],
index = dates)

[9]
Discovering Diverse Content Through
Random Scribd Documents
fust. ’Twas ’long back in ’59, purty long spell ago, an’ the bark Janet,
hailin’ from Westport, was a-cruisin’ fer sparm in the Pacific ’long
’bout the equator an’ ’bout a hundred an’ ten west. Eve’ything’d
been a-goin’ fust rate an’ one o’ the boats made fast to a bull whale
late in the arternoon and by the time he’d spouted blood an’ turned
fin-up, ’twas purty near night. Wall, they got their fluke-chain round
the critter all right an’ was a startin’ to pull him to the Janet, what
was hull down, when a heavy sea caught the boat jes’ right an’
capsized her. ’Course ’twan’t much trouble to right her, but
everything they had was lost—kag o’ water, biscuits, compass,
lantern an’ all fittin’s—an’ while the crew got her right side up in a
jiffy they couldn’t bail her out ’cause o’ the bucket an’ bailer bein’
gone. An’ I tell ye, ’tain’t no picnic tryin’ to keep a water-filled boat
right side up in a heavy sea an’ blowin’ a holy gale. Some reason or
t’other the ship hadn’t seen ’em an’ they couldn’t signal the bark, an’
to keep the boat from capsizin’ again they lashed the oars ’crost her
an’ worked her over ’longside the dead whale and done their best to
tip her up an’ dump the water outen her. But ’twan’t no ’arthly use
count o’ heavy seas a-breakin’ over ’em an’ at last they give up and
started a paddlin’ their way toward the Janet’s lights what was
vis’ble. They kep’ at it all night, an’ come mornin’, they found as they
was farther off than before, so knowin’ they was jus’ usin’ of their
strength for nothin’ they let her drift. Nex’ mornin’ the wind let up a
mite an’ the sea went down, an’ the men managed somehow to
capsize the boat an’ git her back on her keel with a bit less water in
her, but while they was a-doin’ of it, one was drownded. Jes’
recollec’ that for forty-eight hours these chaps hadn’t had nary a
drop o’ water nor a bite to eat and had been a-lyin’ in salt water up
ter their armpits and ye can’t blame two more on ’em fer goin’ crazy.
Derned if ’tain’t a wonder they didn’t all go mad. There they was,
driftin’ about in the middle o’ the Pacific jes’ under the line without
nothin’ to eat or drink an’ the nearest lan’, Cocos Islan’, more’n a
thousan’ miles away. Not one o’ the crew was strong enough to pull
oar, but by workin’ like blazes they managed for to tear out the
boat’s ceilin’ and lashed it up like a sort o’ sail an’ started off afore
the wind.
“For seven days they sailed on with nothin’ to eat or drink ’cause
there wasn’t so much as a drop o’ rain fell, an’ all the time under the
blazin’ sun o’ the ’quator. By that time, things got so bad they begun
to draw lots an’ one o’ the men was killed an’ t’others eat him up.
An’ then, jes’ as if Almighty God had a-taken pity on ’em, a shower
come along an’ give ’em plenty to drink. On the eighth day arter
being adrift, another man died, but nex’ day another shower come
along an’ a big dolphin flopped right into the boat. Ye can’t tell me
there ain’t no sech thing as Providence arter that, an’ every day
arter then a bird’d come so clost the men could cotch him, an’
twenty days arter leaving of the whale, they sighted the Islan’.
Gettin’ ashore, they killed a wild pig and they was a-dinin’ like kings
offen him an’ a eatin’ of coconuts when the old Leonidas, with Pem
Potter aboard as cabin boy, run inter the Cocos fer water an’ found
’em.”
“That’s a fine story,” declared Tom. “It does seem as if they were
saved by a miracle.”
“Yes, and if any one read it in a book they wouldn’t believe it,”
added Jim.
“Tha’s right,” commented one of the New Bedford boat steerers.
“Me, I myself, one time mek long row in da whale boat. Mebbe you
like hear heem, yes?”
“Sure we would,” Jim assured him. “Go on, Manuel, and tell us the
story.”
“Alla right,” assented the boat steerer, showing his white teeth in
a pleased smile. “You know heem, da Pedro Varela schooner, no?
Well, two, three year ago, me, myself, I was boat steerer on heem
when he mek da cruise for da sperm whale een Atlantic. We mek
fine cruise an’ fin’ plenty whale an’ pretty near fill up down by da
islan’s an’ da Cap’n he say he think mebbe he strike two, three more
whale an’ fill up on da way home. So he mek da course north an’,
sure thing, we fin’ da whale jus’ by Bermuda, mebbe leetle way
south an’ eas’.
“Oh, boy, I, me myself, tell da worl’, we fin’ heem! One day da
lookout, he sing out, ‘There she blow,’ an’ da other lookout he sing
out same leetle minute, ‘There she blow,’ an’ we see ten, twelve,
one dozen mebbe, blowin’. He on’y three boat ship, da Varela, an’ da
cap’n an’ mate an’ secon’ mate, they all lower. Me, myself, I was in
da secon’ mate boat an’ got fast da firs’. Long time me, myself, I
been whalin’ an’ never not een my life do I see whale so mad. Oh,
boy! Firs’ thing he sound, six hundred fathom he go, two line, an’
then he breach so dam queek we no can pull in da slack an’ he mill
an’ then, Santa Maria! He mek off all same like he goin’ for tow us to
Flores. Never, never, do I see one whale go like that. One whole
hour he run an’ leetle by leetle we draw in an’ then, jus’ when we
think we get heem, da iron draw an’ we los’ heem. Then we look
’roun’ an’ no see da Varela nowhere. No, sir, I, me myself, I tell you
we los’. Mebbe, we think, da Varela fin’ us in da night, so all da night
we burn lantern lash to da oar an’ stick eet up, but da schooner she
no come an’ when da day come da mate he say, ‘look like we bes’
row home, boys.’ So we eat leetle biscuit an’ drink leetle water an’
head nor’wes’ and row all day. Nex’ day jus’ da same; eat leetle,
leetle biscuit, drink leetle, leetle water an’ row. Third day—’bout six
bell—biscuit he all finish an’ water he finish, too. Then we feel
mighty seek, I myself, I tell da worl’, an’ we row an’ row an’ ’bout
four bell, mebbe, we see smoke. Pretty soon we see da steamer an’
come our way an’ we signal an’ he see an’ come near. He spik us an’
want tek us aboard, but da mate he ask heem where he boun’ an’
when he say ‘Englan’,’ da mate he ask us eef we want go Englan’ an
we all say no. So da mate he say we not go aboard, but if he give us
grub an’ water an’ course for New Bedford, we thank heem ve’y
much and row home. Da skipper of da steamer he say we crazy, yes,
an’ laf; but he give us plenty grub an’ water an’ da course and we
eat plenty an’ row an’ bimeby we see Gay Head light an’ we mek
New Bedford.”
“Gosh!” exclaimed Jim. “You mean you rowed a whaleboat all the
way from Bermuda to New Bedford? How far is it?”
“Me, I don’ know, mebbe three, four hundred mile,” replied
Manuel.
“Bout eight hundred,” volunteered Cap’n Pem. “Purty consid’ble of
a row, eh?”
“Shure, ’twas thot!” exclaimed Mike. “B’gorra Misther Potter, did
yez iver see a sphirit at say?”
“Nope!” replied the other. “Derned if I hev, ’ceptin’ in bottles.”
“Ah, gwan wid yez!” went on the bo’sun. “’Tis not that kind Oim
afther mainin’ at all, at all. An’ if yez hasn’t, thin, b’gorra, Oive seen
somethin’ phwat yez haven’t an’, be the Saints, ’tis a wonder ye’ll
admit it. Would yez loike to hear about ut, b’ys?”
“Yes, indeed, Mike,” said Tom with interest. “Go ahead and tell the
yarn. I’ll bet it’s a corker.”
“Will, thin,” began Mike as he stuffed a load of tobacco into his
pipe. “Oi said ’twas a sphirit, but I dunno if ’twas aither—but ’twas
somethin’ quare an’ sooper-natural-loike. But shure an’ Oim gittin’
off me course so Oi’ll ’bout ship an’ be afther sthartin’ on a new tack.
’Twas ’bout thirty year ago, afore ships wuz a-talkin’ wid woireless,
ye moind, an’ Oi wuz furrst mate av a wee shmall staymer what wuz
afther tradin’ ’twixt Cuby an’ Noo Yorrk, an’ proud Oi wuz to be a
threadin’ the bridge wid the best av thim, Oi’ll tell yez. Will, wan
thrip, phwat did the skipper do but git took wid the yaller Jack an’
doi,—may his soul rist in pace. An’ b’gob, there Oi wuz, masther av a
trim little ship as iver wuz. Faith though, ’twas a grrand falin’, but
with a hape o’ raysponsibility, b’gorra. Thin, wan night, Oi was a-
sittin’ in me cabin on the bridge wid the second mate on watch an’ a
thinkin’ o’ the foine future Oi’d be afther havin’—niver dramin’, b’gob,
thot Oi’d iver be afther a-killin’ say iliphants in the back o’ beyont—
bad cess to the dhrink,—whin all av a suddin Oi sees a figure a-
sthandin’, or a-flyin’, or a floatin’—faith, Oi dunno which—in the air
fornist the port bow o’ the ship. B’ the Saints! ’Twas dramin’ Oi
thought Oi wuz, an’ Oi lept up an’ rubbed me ois an’ says Oi to
mesilf, says Oi, ‘Sure Mike is it sayin’ things ye arre or is it not.’ But
b’gorra, there she wuz—for ’twas a woman sphirit she wuz—a
floatin’ or a-flyin’ along an’ a beckonin’ to me wid her arrm. Says Oi
to the secon’ mate’ say Oi; ‘Misther Thompson,’ says Oi, ‘will yez look
to two p’ints offen the port bow,’ says Oi, ‘an’ tell me do yez see
annythin’.’ ‘Aye Sir,’ says he, ‘Oi see a cloud,’ says he, ‘an’ nothin’
more,’ says he. So thin Oi thinks to mesilf; ’tis a hallo-sue-nation
ye’re havin’, think Oi, an’ Oi looks the other way an’, Saints presarve
me, if there wuzn’t the colleen again, an’ as Oi sees her she sort o’
flits acrost me bows an’ off to port agin, a-beckonin’-loike all the
toime. So Oi says to meself, says Oi, ‘Shure Mike, ’tis a predomition
ye’re afther havin’ or a message o’ some sort an’ the spirit’s been
sent yez to guide yez.’ So Oi says to the second, says Oi, ‘Mr.
Thompson, starboard the helm a bit,’ says Oi, an’ as the bow swings
to port Oi sees the spirit a-swingin’ a bit further ’til me bow’s a-
headin’ six p’ints off me course, an’ thin the spirit sthops movin’ an’
jist floats aisyloike over me bow, so Oi says, ‘Steady as she is, Mr.
Thompson,’ an’ bein’ a good sailorman he niver asks why in blazes
Oi’m runnin’ off me course six pints. For two hours we run an’ thin,
b’gorra, the lookout sings out, ‘Ship afire ahead!’ an’ there, plain as
the nose on me face, Oi could see the glow o’ a burnin’ ship, an’
with that, the spirit disappears an’ Oi know she’s been a-guidin’ av
me to save thim that’s on the burnin’ ship. Full spheed ahead, Oi
rings, an’ nearer and nearer we comes, an’ we kin see the flames o’
the burnin’ ship an’ her sphars an’ all. An’ b’gorra, through me
glasses Oi sees folks a-sthandin’ aft wid the flames not twenty fate
from thim an’ no boats over at all, at all. ’Twas a race fer loife,
b’gorra, for me staymer was a shakin’ an’ a throbbin’ what wid the
spade av her fit to bust, an’ the flames a-racin’ aft on the barrk.
Thin, as I get widin’ hailin’ distance, a man sings out that there’s
powder aboard an’ the hooker’ll be a blowin’ up in a minute more.
Shure, an’ may Hivin help me, if Oi wuz not in a foine fix! Shure, if
Oi wint alongside to save the sowls aboard the barrk ’twould be loike
Oi wud lose me ship, an’ if Oi didn’t ’twould be nothin’ short o’
murtherin’ the folks on the barrk, an divvil a bit o’ toime wuz there
to be a lowerin’o’ me boats. ’Twas between the divvil an’ the dape
say, Oi wuz, wid the divvil holdin’ the thrump carrds. But b’jabbers,
Oi made up me mind an’ do yez know phwat Oi did?”
“No,” cried Tom excitedly. “What did you do?”
“Phwat would yez do, Misther Potter?” queried the bo’sun.
“Derned if I know,” replied Cap’n Pem. “Spit it out, ye ol’ sinner,
what did ye do?”
Mike grinned. “Shure,” he replied, “Oi woke up!”
“Dern yer ol’ hide!” exploded Pem. “I’ll git one over on ye fer that,
blowed ef I don’t.”
“Was you ever shipmates along of a mutiny, Mister Potter?” asked
one of the men, when the merriment over Mike’s joke on Cap’n Pem
had subsided.
“Can’t say as I was,” admitted the old whaleman. “Heard lots o’
yarns ’bout ’em, though.”
“Well, I can beat you there,” asserted the other. “’Cause I was
’board a ship what had a mutiny.”
“Tell us about that,” begged the boys.
“Well, ’twasn’t much of a mutiny,” went on the man, “but I guess
’twas ’bout the funniest mutiny ever was, at that. Manuel, speakin’
’bout the Pedro Varela, minded me of it, ’cause that’s the ship ’twas
on.
“I’d shipped as seaman an’ ’thout countin’ me an’ my two mates
an’ the officers, what was Portugees, every man was a greenie. ‘All
American crew,’ they called it, but I’ll bet my lay ’gainst a chew of
tobaccer there wasn’t two real Yanks in the bunch. Worst set of
bums I ever see, an’ not casting no reflections on present company.
Officers couldn’t do nothing at all with ’em—never did learn the
riggin’, even though the Varela’s just a fore-an’-aft schooner,—an’
didn’t have enough gumption to pull a boat decent. Just the same,
things went along pretty well an’ we got a little oil; but along about
six weeks out, the men commenced for to get tired of whalin’ an’
wanted to get ashore,—grumbled a bit an’ cussed the skipper an’ all,
but no open complainin’ an’ nothing particular to complain about.
Then, one morning, Chips come runnin’ an’ a cussin’ an’ saying his
tool box had been stole. Hunted every place, but tools had just
nat’rally disappeared. Next morning, along comes the cooper
swearin’ his tools an’ the grinstone’d gone. Next morning, ’twas the
blubber-kettles missin’ an’ by that time things begun to look mighty
serious an’ funny. Skipper had all hands aft, but every man-jack
swore he didn’t know nothin’ an’ there wasn’t no proof that they did.
While the Old Man was chinnin’ the lookout sighted a whale an’ the
skipper left off an’ ordered the crew to the boats, an’ what do you
think happened? Why, bless you! There weren’t an iron or lance or
fluke-spade or any darned thing in any one of the boats. ’Course
there weren’t no use in lowering, an’ believe me, there was some
skyhowlin’ rumpus on the old Varela when the Portugee skipper let
loose. But he couldn’t do nothing. There we was, on the high seas a-
cruisin’ for sperm, an’ not an iron on the ship for to get ’em with. An’
when we got to searchin’ about we found there weren’t a spade or a
blubber-hook or a cuttin’ in tackle, neither. Of course, we all knew
what ’twas. That crew of bums had just heaved every darned thing
over the side long in the night watches an’ knowing if the skipper
couldn’t catch whales, he’d nat’rally have to make port. Well, there
weren’t nothing left for him to do but make port so, talkin’
something fierce in United States and Portugee, he heads for Fayal
swearin’ to clap every man-jack in irons soon as he got there. Worst
of it was he blamed every mother’s son of us, Yanks as well as the
greenies. When we made Fayal, there, big as life, was a Yankee
cruiser an’ soon as we got near, up goes a signal for assistance and
a-sayin’ there’s a mutiny on board.
“I dunno whether them navy men was so tickled at the fun of the
thing or what ’twas, but the up-shot was they had us all aboard an’
talked a bit, though I knowed they was a bustin’ themselves tryin’
not to laff, an’ after a heap of questioning, they let all but eight of us
loose an’ ironed the others an’ took ’em home for trial. I was on the
beach but got a ship after a bit an’ when I got back to New Bedford
I heard the rest of the story. Seemed this ’ere mutiny was a new
kind. No law’d ever been made to cover it an’ accordin’ to law the
men hadn’t mutinied—didn’t use violence nor threaten nobody nor
disobey orders—so they couldn’t be charged with mutiny. Then the
owners tried to get ’em sent up for theft or destroyin’ property or
most anything, but there weren’t no proof of nothing, so the judge
finally sentenced ’em for disorderly conduct an’ they got ten days
each.”
“I heerd ’bout that,” commented Cap’n Pem. “Wisht they’d been
my crew. I’d a-heaved ’em over after them fittin’s. Derned if I
wouldn’t. But look-a-here! It’s a-gittin’ too late ter be a yarnin’ with
killin’ to begin in the mornin’. All han’s turn in!”
An hour later, only the protesting croaks of sleepy penguins and
the distant barks of the sea elephants broke the silence that reigned
over the island.
CHAPTER X
LOST

Early the next morning, preparations for the killing began. Armed
with clubs, tin pans, flags and pieces of cloth, the men made their
way along the beach between the big herd of elephants and the sea,
and took up stands at intervals of a few hundred feet apart. Then, at
a signal from Cap’n Pem, they advanced towards the elephants,
shouting, hallowing, beating on their tins, waving their cloth and
flags and jumping and prancing about like a lot of savages.
Frightened and surprised at these strange figures advancing towards
them, and dazed by the noise and fluttering rags, the huge, timid
creatures hobbled and wriggled their way up the shingle, wrinkling
their noses and barking in terror and stupidly getting further and
further from their native element in their sole desire to keep away
from the men. Wedged together in a closely-packed mass, the giant
seals impeded one another’s progress and added to their terror until,
presently, their retreat was a wild stampede towards the higher
ground some distance from the sea.
It was a strange and remarkable sight to see these immense,
powerful creatures with their strong, sharp teeth striving to escape
the men and as frightened as a flock of sheep, when any one of the
monsters could easily have crushed a man’s head in his jaws with a
single bite. To the boys, it seemed pitiful and they were really sorry
to think of such harmless, splendid creatures being thus ruthlessly
slaughtered merely for the sake of their oil. But their sympathy for
the elephants was not as great as it would have been had the
animals appeared more helpless and gentle, for despite their
timidity, the sea elephants, and especially the old bulls, were savage,
ferocious-looking beasts. Naturally ugly, even when at rest, they
appeared veritable monsters as their small, wicked eyes gleamed red
and bloodshot, their trunklike snouts lifted above their great red
mouths, their huge, sharp teeth gleamed and snapped and their
snarling barks filled the air with a deafening roar.
Although they had been assured that the elephants were harmless
and had been eye witnesses of the fact that the men could walk
among them, kick them and even kill them without the least attempt
at resistance on the animals’ part, yet neither Tom nor Jim could
summon up enough courage to approach within reach of the waving,
threatening heads and snapping jaws. But the men had no such
fears and when, at last, the herd had been driven to the selected
spot, they went among them, driving the big, full-grown animals into
small bunches and ruthlessly clubbing them over the heads.
As the killing began and the heavy bludgeons thumped on the
heads of the elephants, their humanlike sighs and screams, their
choking, gurgling death coughs and the terrorized barks of their
fellows were more than the two boys could stand. Hurrying from the
scene of the slaughter, they made their way past the camp and
started up the hillside beyond. It was hard climbing, for the sharp,
volcanic rocks made footing uncertain, the scant gray moss and
lichens and dried stiff grass were slippery and the hill was steep.
Here and there, albatrosses were squatting on the ground and when
the boys approached they merely hissed and struck out with their
strong, hooked beaks, refusing to move. They were such enormous
birds and appeared so vicious with their china-blue eyes and
menacing bills, that the boys had no desire to get at close quarters
in order to see if they had eggs; but they soon discovered that by
shooing at the birds and showing no signs of fear they could force
the albatrosses from their nests and they were greatly elated at
sight of the enormous, rough, brownish eggs in little hollows of the
stony ground.
Amusing themselves with the albatrosses, and taking their time,
the boys reached the summit of the hill and seated themselves upon
a rock ledge to rest. From where they sat, they could look down
upon the camp and the beach and could see the men, still busily
killing the elephants. But the slaughter evidently was nearly over,
and presently, they saw the men stooping over and evidently
engaged in stripping the skins and blubber from the carcasses. In
the other direction, they looked down upon a sloping hillside ending
in a small, bowl-shaped valley which the boys at first sight thought
filled with snow; but a second glance showed it to be covered with
great white birds.
“I wonder what they are,” said Tom. “They don’t look like
albatrosses and they’re not penguins. Let’s go down and see.”
Rising, the boys were about to descend when their attentions
were attracted by peculiar sounds apparently issuing from the earth
under their feet.
“What’s that?” ejaculated Jim. “It seems to come right out of the
ground.”
Getting on their knees, the boys searched everywhere among the
rocks, expecting to find some strange creature in hiding there, but
while they searched diligently, and although the queer grunting
sounds continued, they could find no trace of any living thing.
Puzzled, they stopped hunting and listened, placing their ears to the
ground, trying to trace the sounds, but to no purpose, for the noises
seemed to come from all about and were so mysterious and baffling
that the boys began to feel nervous.
“It’s the weirdest thing I ever heard,” declared Tom. “I’m
beginning to think the place’s haunted.”
At last, giving it up as a bad job, the two boys started forward
and a moment later clambered down over a projecting mass of huge
irregular rocks. The next instant they stopped short, for the baffling
sounds came clear and distinct from among the rocks. Approaching
cautiously, the boys peered into the dark cavelike openings and the
next moment burst into laughter.
“There’s the ghost,” exclaimed Jim, “I wonder what they are.” Far
in among the bowlders were several snow-white birds with pretty
pinkish or salmon-colored bills and bright, beady eyes. Reaching in
his arm, Tom seized one of the creatures, and despite its protests,
drew it out and revealed two handsome brown eggs where it had
been sitting.
“Oh, I know now,” declared Tom. “It’s a sheathbill, don’t you
remember Cap’n Pem pointed them out to us at sea. Look, here’s
the sheath on its bill.”
Satisfied at having solved the mystery of the strange sounds, and
having identified the bird, the boys released the creature which
immediately fluttered back to its nest, ruffling its feathers and
croaking in such an indignant, offended way that the boys roared
with laughter. Continuing down the hill, the boys approached the
first of the great bird colony in the valley and found they were big,
white Molly Mokes and another species of bird which they had not
seen before.
“They’re some sort of albatrosses,” insisted Tom. “But they’re not
like the others. They’re smaller and have bright yellow beaks and
they’re much whiter.”
“Yes, and they’ve greeny-brown eyes instead of blue,” added Jim.
“I’ll bet I know what they are,” Tom announced “I’ve been
thinking, and I remember reading about a kind of albatross called
yellow-nosed. These have yellow noses so I’ll bet that’s what they
are.”
It was a strange sensation for the boys to find themselves
surrounded by countless thousands of the big, white birds which
showed not the least fear, but pecked boldly at the boys’ garments
as they picked their way among the nesting birds.
As they gained the farther side of the valley they came to a low,
rocky ridge, and curious to see what lay beyond, they clambered up
its side and found themselves once more in view of the sea.
“Look at those penguins!” cried Jim, as he caught sight of a great
flock of the queer birds. “Gee, but they’re big fellows!”
“They’re not like the others,” replied Tom. “Say, we are finding a
lot of queer things to-day.”
“And those don’t look like sea elephants on the beach either,” said
Jim. “They look smaller and different, somehow.”
“I believe you’re right,” agreed Tom. “Let’s go down and have a
look.”
As they approached the creatures basking upon the shingle, the
boys saw that they were indeed very different from the huge sea
elephants, for they were much smaller, they lacked the long snouts
and their bodies were darker in color and beautifully spotted.
“Don’t let’s go too near,” exclaimed Jim. “I don’t like their looks.”
“Oh, don’t be a fraid-cat,” urged Tom. “They won’t hurt us. Of
course, we won’t go among them. I don’t trust them as much as all
that.”
Rather nervously, but anxious to see the odd creatures at closer
range, the boys walked towards the herd of animals and were within
a few rods of the nearest when the giant seal suddenly reared
himself up, opened a huge red mouth filled with enormous, sharp-
pointed teeth, and with a bellowing howl threw himself bodily
towards the two boys. Instantly, with terror-stricken cries, the boys
turned and fled, never stopping until they were well up the hillside.
“Gosh, but he was fierce!” ejaculated Jim, when they regained
their breath. “I told you we’d better not go near.”
“You can bet I won’t, next time,” Tom assured him. “But they’re
no sea elephants anyhow.”
“Let’s go along the beach and have a look at the penguins,”
suggested Jim. “We can keep away from those beasts, back here.”
Giving the fierce, spotted seals a wide berth the two boys
descended to the beach and strolled towards the penguin colony.
Many odd shells and other interesting things were scattered on the
sand, and, as the boys stooped to pick some up, they noticed many
rounded, glittering pebbles.
“Why, they’re moonstones!” exclaimed Tom, “and thousands of
them!”
There was no question of it. The beach was strewn with the
translucent, handsome stones and the boys busied themselves filling
their pockets with the gems. So intent were they, that they failed to
notice a low, gray cloud about the mountain top which drifted down
towards the shores in little wisps and detached masses until, feeling
chilly, Tom looked up and gave a surprised cry. On every side they
were surrounded with an impenetrable, dense fog and only a small
area of the beach about them was visible.
Seaward they could see the lazy, green rollers coming
mysteriously from a gray bank. They could hear the muffled cries of
birds and the occasional flapping of wings; but not a sign of the hill
or of the mountains could be seen.
“Gosh, we’d better be getting back!” exclaimed Jim anxiously. “It’s
getting thicker every minute.”
Hurrying from the beach, they commenced climbing the hill, but
long before they reached the summit the beach and waves were
hidden from view and the boys seemed shut in as if by a soft, gray
wall.
“We’ll have to be careful or we’ll get lost,” cautioned Tom. “We
should have brought a compass.”
“What good would that do?” demanded Jim. “We don’t know what
direction the camp is.”
“No, but we could be sure we were not moving in a circle,”
explained Tom sagely. “But come along, we can find that Molly Moke
rookery and then go up the hill and find the cave where the
sheathbills are and go straight down from there.”
Striving to keep a straight course by listening to the breaking seas
at their backs, the boys picked their way over the ridge, and
descending the further side, were overjoyed to find themselves
among the nesting Molly Mokes.
“We’re all right now!” said Tom confidently. “If we walk straight
across and up the hill to the cave we can’t go wrong. Why, I don’t
believe we went over half a mile from camp anyway.”
Shut in by the dense fog, the boys could hear the disturbed cries
of the thousands of birds about them, but the birds themselves were
only visible when within a few feet and even then they had a
strange, ghostly appearance. Several times the boys actually
bumped into them, and they were constantly compelled to turn to
right or left to avoid stepping on the birds. But at last, they reached
the scattered, outlying nests and found the ground rising before
them.
“Funny, this hill doesn’t seem half as long as it did before,”
commented Jim as they gained the summit. “Say, listen! What’s
that?”
For a moment the two paused, straining their ears to catch a faint
sound that issued from the fog ahead. And then, as the truth
dawned upon them, they gazed at each other in dismay. The noise
was the breaking waves. They were back at the spot from which
they had started. They had walked in a circle and were lost!
Presently, however, as they recovered from the disappointment and
shock of their discovery, their confidence returned.
“We’ll have to try again,” declared Tom. “We must have got turned
around among those Molly Mokes. I’ve a scheme, Jimmy. When we
get there this time, we’ll separate a little and one of us will walk
ahead a few yards and then stop, and then the other can walk
straight to him and then stop and the other can go on ahead as far
as he can be seen and stop and in that way we might be able to go
pretty straight. Anyway, we won’t go in a circle.”
“That may help,” admitted Jim, “but we’ll have to kick the birds
out of the way to do it.”
“Bother the birds!” ejaculated Tom. “We’ve got to get to camp.”
“I wonder how long fogs last here,” said Jim as once more they
made their way up the ridge. “Perhaps if we just waited a while it
would lift.”
“I don’t know,” replied the other, “but I heard Cap’n Pem say that
sometimes the island’s foggy for weeks at a time.”
Once again they reached the Molly Moke rookery and at once
proceeded to put Tom’s plan into practice. By shoving the birds out
of their path and ruthlessly trampling on the eggs, the boys made
their way across the valley in a fairly direct line; but as they gained
the slope of the hill a sudden misgiving seized Jim.
“Say, Tom,” he exclaimed, “how do we know we’ve crossed in the
right direction? Don’t you remember the hill went all around the
valley—it was like a big bowl—and we may be on the opposite side
from where we came down.”
“We can’t help that,” stated Tom. “When we get to the top we’ll
mark the spot and walk to the right ’til we find the sheathbills’ cave
and if we don’t find it, we’ll come back and try to the left.”
Toiling up the hillside, panting with the exertion and soaked to the
skin by the clinging moisture, the two boys at last reached the
summit.
“Perhaps they’d hear us in camp if we yelled,” suggested Jim.
But their cries seemed muffled in the fog and no answering call
came to them, so, piling several stones in a little pyramid, the two
turned to the right and carefully picked their way along the rocky
ridge.
“We didn’t come over at this place, I know,” said Jim decisively as
they came to a jagged, upstanding mass of rock.
“No,” admitted Tom. “but it may have been just a little to one side
of the place where we did cross. Come along.”
In order to pass the ledge, the two boys were compelled to
descend a short distance on the hill and so dense was the fog on the
summit that the rocks disappeared from sight ere they had taken a
dozen steps. Judging that they passed the obstruction, they once
more turned up the slope and tramped on, hoping each moment
that they would be in luck and would come upon the pile of
bowlders where they had discovered the sheathbills.
“Say, we must have been way off our course,” panted Jim at last.
“We’ve been walking for half an hour and seems to me we’re going
down hill.”
“I thought that too,” replied Tom, “but I guess it’s just the effect
of the fog.”
For ten minutes more, the boys continued and then, coming to a
mass of fallen rock, they found further progress barred by a bold
perpendicular cliff.
“Well, we can’t go any further,” observed Tom. “Now we’ll have to
go back and try the other direction.”
“I’m going to rest first,” insisted Jim. “There’s no use in getting all
tired out.”
Seating themselves upon a piece of rock, the boys were talking
over their predicament when, suddenly, there was a cracking sound.
The boys felt their seat moving and leaped aside as the mass of rock
gave way and went crashing down the hill. But while the boys had
saved themselves from an injury, yet they had not saved themselves
from a tumble, and as they jumped from the rock their feet shot out
from under them and rolling and sliding, they followed after the
stone for a dozen rods before they could check their headlong
course.
At the same instant they heard a tremendous crash from below
followed by a shout:
“Hi, there! What’n tarnation’s broke loose? Derned ef the whole
mounting ain’t a-tumbling down!”
With wild yells the boys leaped to their feet, and regardless of
danger, raced down the hillside. Before they had covered a hundred
feet they reached level ground and plumped full into Cap’n Pem,
bowling the old man over like a ninepin.
“Avast there!” spluttered the old whaleman. “What in
thunderation’s up? Fust a chunk o’ mounting an’ then you two
scallawags! What in Sam Hill ye in sech a hurry fer? Bear a chasin’
on ye?”
“No,” stammered Tom. “We were lost. Where are we?”
“Where be ye?” reiterated the old man. “Where be ye? Why, right
’longside o’ the shack a course. Where’d ye think ye wuz? Derned
queer way ye have o’ comin’ home!”
CHAPTER XI
A STRANGE MESSAGE

The boys actually had tumbled into camp from the hill behind the
shack, and they joined heartily in the laughter of the men, when
they related their story of being lost in the fog.
“Shure, an’ Oi wuz a-sayin’ to Misther Potter that maybe yez was
lost,” Mike affirmed, “an’ twas meself what wuz for goin’ afther yez if
yez didn’t turrn up soon.”
“Gid out!” jeered Cap’n Pem. “Ye’d be a fine one ter go
gawallupin’ over these ’ere hills with that there wooden lig o’ yourn.
Know’d the boys ’ud git in ship-shape.”
“B’gorra thin, Oi could do as well as yez at anny rate,” insisted
Mike.
Cap’n Pem snorted, but forbore a retort and warned the boys
against taking any risks in the future.
“Don’t ye never go off without a-takin’ a gun an’ a compass,” he
commanded them. “An’ ef ye go out o’ sight o’ camp, mind ye watch
the way ye’re a-goin’ of. ’Tain’t no jokin’ matter ter git lost here. It’s
a heap bigger islan’ than ye think an’ fog’s li’ble ter come on any
time.”
When the boys told of their experience with the big seal-like
creatures, Cap’n Pem laughed uproariously.
“Them’s sea leopards,” he told them. “Lucky ye didn’t git too clost,
they ain’t like these ’ere elephants. Bite ye quicker’n Jack Robinson,
’bout as fierce as a lion an’ mighty touchy too.”
“Aren’t they good for anything?” asked Tom. “Do you ever kill
them?”
“Hides is wuth somethin’,” replied the old man, “but ain’t got
enough blubber ter make ’em wuth the danger o’ killin’ of ’em. Time
was, when we used fer to hunt ’em an’ fur seals, too. But ’ain’t
nothin’ in it now, with elephant ’ile so high.”
Cap’n Pem also explained that the big penguins they had seen
were King Penguins and that the moonstones, though pretty, had
little value.
“Whole beaches on ’em over ter Kerguelan,” he told them. “Took
up derned nigh a bucket full on ’em one trip. Couldn’t sell ’em fer
’nough ter keep me in terbaccy. Guv ’em all ter the wimmin folks.”
Boiling was going on when the boys reached camp, and after
eating, for they were ravenously hungry, they watched the operation
for some time and then made their way towards the spot where the
men were stripping the blubber from the last of the dead elephants.
Everywhere, the enormous raw carcasses were scattered about, and,
almost hiding them from sight, were thousands of albatrosses, Molly
Mokes and other sea birds, screaming and quarreling over the feast
and tearing the flesh from the bones with their powerful bills. So
bold were the birds that they frequently swooped down and
attempted to carry off pieces of blubber under the noses of the
working men and one man constantly was kept busy shooing and
beating them off.
“Wouldn’t they clear out if you shot some of them?” inquired Tom.
“Yep, I expect they would,” replied a boat steerer, “but we need
’em an’ don’t want to drive away. What’d we do with all them there
dead elephants if ’twan’t fer them birds? Why, they’d smell so ye
couldn’t live on the islan’, an’ a breedin’ plague.”
“Do you mean the birds will eat them all up?” asked Jim in
surprise.
“Sure thing,” declared the sailor, “less’an a couple o’ days there
won’t be nothin’ but bones left.”
The boys could scarcely believe that the birds could completely
devour the mountains of flesh before them, but long before the
expiration of the two days only the clean picked bones of the
elephants marked the scene of their slaughter.
As it was light through the night, the work of boiling was carried
on unceasingly, the men working in watches or shifts, as on board
ship, and by the second day they were ready for another drive and
kill.
Although practically all the large elephants had been slaughtered
the first day, yet there seemed to be no decrease in the numbers
which came up the seashore daily, and the second killing was even
larger than the first. Cap’n Pem and the men were elated, for the
great number of elephants argued well for a full cargo of oil, and the
old whaleman couldn’t say enough in praise of the policy of the
British government in having restricted the killing and extermination
of the creatures.
“Las’ time I was here,” he informed them, “they’d got so pesky
skeerce ye couldn’t make a kill o’ a dozen a week an’ now look at
’em. Jes’ a crowdin’ o’ thersel’s up, a-waitin’ ter be killed. Looks like
as though they ac’t’ally enj’yed it.”
Not forgetting Cap’n Pem’s injunction regarding gun and compass,
and usually carrying a lunch with them, the boys spent their days
wandering over the hills, exploring the island, gathering eggs from
the more remote bird colonies, so as not to frighten away the
scavengers near camp, and having a glorious time by themselves.
They had discovered several small ponds among the more distant
hills and here, to their surprise, they found a number of small teal-
like ducks. These proved excellent eating and a most welcome
change in the camp diet and the boys made almost daily visits to the
place. On another occasion, they had found a rookery of the
Antarctic fur seals and spent hours watching the big, gentle-eyed
creatures frolicking and playing about. Twice too, they had
clambered far up the mountain side and had gazed forth upon the
vast panorama that was stretched beneath them. Rugged and gray,
their own island spread itself below their feet, and on the horizon—
some visible across lanes of gray sea that from the height seemed
narrow, others but hazy clouds against the sky and others only
distinguishable by their lofty peaks—were many other islands of the
group. The boys, who had spent hours poring over charts of the
Antarctic, knew many of them by name, such as Governor
Livingston, Scotts, Clarence and Deception. The latter was the island
to which the Hector had gone and the boys spent much time in
speculation as to the success the men were having there and how
soon the bark would return.
But best of all, the boys loved to visit the rookeries of albatrosses,
penguins and Molly Mokes that by now were filled with ungainly,
grotesque and mirth-provoking fledglings.
It was while they were on their way to one of these, several
weeks after their adventure in the fog, that the boys saw a big
Wandering Albatross acting in a most peculiar and unusual manner.
The bird was standing upon a pile of rocks and was spreading and
flapping his enormous wings as if trying to fly, but he would rise only
a few feet above the ground before he again dropped back. Then he
would reach down, peck at something in the rocks as though
feeding, and again flap into the air for a short distance again to
repeat the whole performance.
“What do you suppose he’s doing?” asked Tom in puzzled tones.
“He acts as if he’d found something and couldn’t make up his mind
to leave it.”
“Come along and see,” suggested Jim, and curious to know the
reason for the big bird’s actions, the two turned aside and clambered
over the rock-strewn hillside towards the albatross.
Much to the boys’ surprise, he apparently paid little heed to their
approach, but continued his remarkable behavior until they were
within a few yards. Then, to their amazement, they saw that the bird
was fastened to the rocks by a piece of rope or line.
“Why, he’s tied down!” exclaimed Jim. “I wonder who did that.”
“I can’t imagine,” replied Tom. “But it’s a shame! He’ll just beat
himself to pieces, or die of thirst and starvation. Come on, let’s untie
him.”
But to release the bird was more of an undertaking than they
bargained for. Every time the boys tried to approach, he would strike
viciously with his enormously powerful wings, hiss like a gigantic
snake and lunge savage, snapping thrusts with his strong, hooked
beak.
“Gee, he is ugly!” cried Tom. “I’ve half a mind to leave him.”
But having once determined to free the bird, the two were not to
be worsted so easily. Taking off their coats, and with Tom holding his
sheath-knife ready, the two boys made a sudden dash at the
albatross, and while Jim threw his jacket around the bird’s head and
held his neck, Tom protected his head from the blows of the wings,
and stooping quickly, cut the line. Then, leaping back, they watched
the great bird as he flapped upwards with cries of triumph and sailed
off out of sight.
“Ungrateful old brute!” laughed Jim. “Acts as tickled as if he’d got
loose all by himself.”
“I wonder what he was tied to,” put in Tom. “Hello! Look here,
Jim!” Reaching down in a crevice of the rocks, Tom drew out a
bundle, or roll of frayed and weather-beaten tarred canvas attached
to the stout, hemp lead-line which had bound the albatross.
“Well, that beats all!” exclaimed Jim as the two boys examined the
package curiously. “It must have been tied to the bird’s leg and got
wedged between the rocks when he alighted. What do you suppose
it is!”
“Search me!” replied the other. “Let’s open it and see.”
Drawing his knife, Tom proceeded to slash through the rope that
was wrapped and tied about the bundle and then commenced to rip
out the tightly drawn stitches with which it was sewn.
“Whoever sewed this didn’t intend it to get away in a hurry,” he
remarked as the first layer of heavy canvas fell back and disclosed
another beneath it.
“Reminds me of the pill-boxes the druggists have,” supplied Jim.
“Just one inside of another right down to a tiny one. Perhaps that’s
all this is.”
“Nobody’d take the trouble to sew it all up and tie it to a bird’s leg
unless ’twas something important,” declared Tom decisively. “I’ll bet
there’s something mighty interesting in it.”
Two more layers of canvas were removed, and as the last was
pulled away, the boys saw a brass tube, or cylindrical box, with both
ends stopped with wood.
“That’s a funny looking thing,” commented Tom as he turned it
about. “Looks like a—gee, I know what ’tis! It’s part of a telescope.”
“Perhaps there’s something in it,” Jim suggested excitedly. “Open
it and see.”
After some difficulty, Tom pried out one of the wooden plugs and
tipped up the cylinder, but nothing dropped out. Then, as he peered
within it, he cried out, “Gosh! There is something in there.”
Inserting his finger in the tube, while the nerves of both boys
tingled with expectancy, Tom drew out a roll of some crinkled,
whitish-yellow material which they thought, at first, was paper.
“Hurrah! It’s a message!” shouted Jim. “Gee, we’re in luck!”
Spreading the parchment on a smooth rock, the two boys studied
the indistinct characters upon it, but for some time could make
nothing of them. Gradually, however, they began to recognize
letters, and slowly and with much hesitation and difficulty spelled
out the following:

“Two hoo shal fine these leter for God sak save mee. iam
reckt on a illan west off elyfant illan in the soth shetlans yu kan
tel the won by too piks stikin up on the eas end i am seemans
off the brig ellen of st Helena we was kroosin an see a worship
she was a gurman an sink us an fir on the botes i was hit an
wen i cum two i seen nothin I drifted a long tyme an most starf
an dye of thurst wen I seen lan i no it was the soth shetlans
cuss i bin theyre bfour too kil elyfonts mi bot drift one these
ilant an I find a ole hut I bin her long tym an I am sik mi wun
want heel i muss dy if non resku me I amm goin two ty this to a
allybtros whut i haf cot mae god dyrect it too sum crishun an
knot two a hun. yurs respekfuli
“Sam Holt
“p. S. i think this is disemper but I do not sur i los trak ov tym
wile i byn sik.”

For an instant, the two boys sat speechless, absolutely


dumbfounded at the story disclosed by the parchment so
miraculously secured.
“Gosh, he’s right near here!” cried Tom, at last. “Say, we’ve got to
hustle down and tell Cap’n Pem. Perhaps we can rescue him!”
Dashing as fast as they could over the rough ground, risking
broken bones and bruises, forgetting all except to tell the old
whaleman of their discovery, the two boys jumped, leaped,
scrambled and ran, until, breathless and exhausted, they rushed into
camp and hurled themselves on the old man.
“Gosh all mackerel!” ejaculated Cap’n Pem. “What’n tarnation’s up
now? Seed a ghos’?”
“Oh, Cap’n Pem!” panted Tom. “We found a message—a letter—
there’s a man—shipwrecked—on an island.”
“West of here!” Jim went on as Tom paused for breath. “See,
here’s the message—found it on an albatross. Can’t we save him?”
“What?” ejaculated Cap’n Pem, while a number of the men
gathered about attracted by the boys’ excitement. “What’s that ye’re
a-sayin’? Man shipwrecked? Found a message on a albatross, eh?
Blow me ef ’tisn’t!”
Then, having recovered themselves, the two boys rapidly told
their story, while the old whaleman studied the message.
“B’gosh!” exclaimed Mike, “’tis a missage all right, all right. Shure,
b’ys, we’ll be afther a rescuin’ av him.”
“Derned if we won’t!” cried Pem. “Nobody can’t say as any Yankee
whaleman ever lef’ a shipwracked mate fer to die ’slong’s he could
help it. Dern them Germans’ hides! Wisht I could git at ’em! Here
you, Mike, call all han’s! I’m a-goin’ fer to ask fer volunteers. An’ git
the boat ready fer the v’yge. Stow away ’nough grub an’ water fer a
week an’ med’cines an’ grog, an’ clo’s an’ blankets. Like as not thet
there feller ain’t got none.”
Then, as Mike stumped off to carry out his orders, Pem bustled
about, giving directions, leaving orders as to work to be done while
the boat was away, and between times, cursing the Germans with
quaint oaths.
“Reckon like as not he’s died long ago,” he muttered half to
himself. “No knowin’ when he writ thet letter.”
“But it says December,” Tom reminded him. “And this is only the
second week.”
“Yep, I knows it,” replied the whaleman. “But he says he ain’t no
ways sure an he don’ say what December. Like as not ’twas las’ year
or year afore. ’Spect we’ll have all our trouble fer nothin’.”
Then, addressing the men who had gathered about, Cap’n Pem
told the story of the boys’ find in a few terse words and called for
volunteers to make the trip. Every hand went up instantly.
“Bile me ef I didn’t know ’twould be thet way!” cried the mate.
“Might as well saved myself the trouble. Got to pick ye out, anyway!”
Hurriedly running his eyes over the men, he picked four of the
strongest and best, and all men from New Bedford. Then, after a
moment’s hesitation, he turned to the one-eyed man, Ned.
“Here, you!” he snapped out. “You’ve been a sojer. Know anythin’
’bout doctorin’?”
“Yes, sir, a little, sir,” replied Ned respectfully. “I was in the field
hospital over there, for a time, sir.”
“Thought so!” ejaculated the mate. “All right, come on, men, git a
move on!”
“But can’t we go?” cried Tom.
“Nope, no place fer youngsters.” Then, as he noticed the
crestfallen look on the boys’ faces, he suddenly relented.
“Oh, blow me! All right!” he burst out. “Hadn’t been fer ye we
wouldn’t a-been a-goin’. Reckon ye gotta right ter go. Come along!”
To the accompaniment of lusty cheers from the men, the boat
was pushed off, the five oars took the water, and with a “Give way
boys!” from Cap’n Pem, the rescuers headed for the open sea.
Straining at their oars as though they were going on a whale, the
men fairly lifted the speedy whaleboat through the water, while, in
the stern, Cap’n Pem stood grasping the huge steering oar and ever
and anon urging his crew to even greater efforts. Rapidly the beach
was left behind, and swinging the boat to the westward and
rounding a projecting, rocky point, the old whaleman steered a
course for the hazy outlines of a distant island.
“Reckon thet’s the one,” he remarked. “’Pears to me I recollec’
them there needles. Used ter call ’em the donkey’s ears.”
For hour after hour the boat sped on. Elephant Island grew dim in
the distance and more and more distinct became the island ahead.
Gradually, from the mist it took form and shape. The boys could see
the rugged, central volcanic cone; little by little the lower slopes
became visible, and at last, Tom gave a shout of joy, for looming up
from the sea at one end of the island were two steep-sided, conical
peaks.
“Thar she be!” announced old Pem. “Give way, lads! If that poor
lad’s a livin’ he’ll likely be a sightin’ of us purty quick.”
Half an hour later, the island loomed close ahead and the boys
strained their eyes in an effort to make out the hut in which the
castaway had lived. But not until they were within half a mile of the
shore did they see it; a little, tumble-down shanty of gray, weather-
beaten boards and ragged flapping sail-cloth tucked into a corner of
the rocks and so nearly like them in color that it was scarcely
distinguishable. But search the beach and rocks as they would, they
could see no sign of life, and their spirits fell, for all began to fear
that they had arrived too late, that the bleaching bones of the
wounded castaway would be all that they would find. Running their
boat upon the shingle, the crew leaped out, and led by Cap’n Pem,
hurried towards the house, hallooing as they went. Then, when
within a score of paces from the hut, a crazy, makeshift door swung
open and a man stepped forth. And at sight of him, every one
stopped short and gazed in amazement. The man was a gray-
headed, coal-black negro with a wooden leg!
“I’ll be everlastin’ly dumbswizzled!” burst out Cap’n Pem. “Derned
ef we ain’t shipped another peg-leg!”
The next instant the old negro rushed forward and threw himself
upon the beach groveling at Pem’s feet.
“Hi, there! Git up!” cried the whaleman. “We ain’t no Saints! Jes’
o’nary whalemen. How be ye anyhow? Reckon we’re in time, eh?
Feared we’d fin’ ye dead an’ gone.”
With tears of emotion trickling over his emaciated, ebon cheeks,
and with wildly rolling eyes and in broken tones, the negro poured
out incoherent thanks and blessings and was so overcome that two
of the men were obliged to carry him bodily into the shack. Here, on
an improvised couch of moss, dried seaweed and bird skins the
castaway was placed, and Cap’n Pem hurriedly poured a stiff draft of
whiskey down his throat while Ned and the men quickly kindled a
fire and proceeded to heat coffee and tinned soup. Between the
liquor and the steaming food the old negro quickly revived and
managed to control his emotions somewhat. Cap’n Pem told him
how they had learned of his plight, but by Ned’s command he was
not permitted to talk; although all were filled with curiosity to learn
his story, and the castaway was compelled to content himself with
muttering, “Thank de Lord A’mighty! De Lord shure does watch over
his pore sinners! Oh, Lor’ is I save’ at las’!”
“Doc,” Ned, as the men called him, declared that the castaway
was in no condition to be moved and that he must have several days
of rest and good feeding before undertaking the trip in the open
boat. The wound of which he had spoken in his message, had partly
healed, but he was very weak from suffering and lack of food and
now that he was rescued he seemed quite content to lie still and be
nursed back to health and strength. Gradually too, he told them of
his life upon the island: how he had managed to eke out a living by
catching crabs and shellfish, and later on by albatross and penguin
eggs; and how he had captured the albatross and had utilized a
broken telescope which he had found in the hut as a box or
container for the message.
“How did you happen to think of sending the message that way,
Sam?” asked Tom. “There wasn’t one chance in a million that any
one would find it.”
“I seed a ship a-sailin’ away fra El’funt Islan’,” replied the negro,
“an’ I knows as how she must’a’ lef’ men there an’ I knows as how
these albatrosses do smell dead meat for a pow’ful long ways, an’ I
thinks like as not if you was a-killin’ the el’funts this ol’ bird mought
go over yander for de food an’ some man mought see the canvas a-
danglin’ from he laig an’ cotch he; an’ praise the Lord A’mighty, you
did.”
Cap’n Pem was anxious to return to the camp as soon as possible
and fumed and grumbled, although “Doc” Ned declared that three
days should be enough rest for Sam with the good care he was
receiving. But when the third day came, a gale was blowing and
lashing the sea to fury and departure was impossible.
“Ding-bust the weather!” exploded Cap’n Pem, when on the next
day, the gale still howled about the shack and cold rain and sleet
beat like shrapnel on its roof. “Didn’t I tell ye we’d have bad luck,—
arter that there bo’sun bird come aboard! Wouldn’t be s’prised ef
this ’ere dumfoozled sto’m lasted all summer. Reckon we’ll be
shipwracked oursel’s here!”
“But we haven’t had bad luck,” Jim reminded him. “I think we’ve
had mighty good luck, to get that message and save Sam.”
“Hadn’t begun, then,” contended the whaleman. “Got ter have a
beginnin’ sometime. Bet ye we gets wuss an’ wusser from now on.”
But despite Cap’n Pem’s dismal forebodings, the next day was
fine, the gale had blown itself out, and while the seas still ran
mountain high, they were rapidly decreasing. Two days later Cap’n
Pem declared the sea had moderated enough to set out and with
one of the men helping Sam—for he was still weak—the party
launched the boat and headed for Elephant Island. It was hard
pulling against the head sea and as there was no favorable wind, the
sail could not be used and the men strained and sweated at their
heavy oars. But gradually the little island faded into the distance and
each moment Elephant Island loomed nearer and plainer ahead. At
last they gained the lee of the land, and keeping close inshore,
pulled towards the outstanding cliffs which concealed the harbor. As
the boat came abreast of the point the spars of a ship came
suddenly into view.
“Hurrah! The Hector’s back!” cried Tom.
“Derned if she is!” exclaimed Cap’n Pem. “That’s a brig. I’ll—” but
his sentence was never finished. From the direction of the shore
came the sounds of a volley of gun shots.
“What’n tarnation,” roared the old whaleman. “Give way, lads! Lift
her! Fightin’s broke loose yonder!”
CHAPTER XII
THE RAIDERS

Meanwhile, upon Elephant Island, things had not been going well.
For the first two days after the departure of Cap’n Pem and his boat,
the work of killing and boiling had gone on as usual, although on a
smaller scale owing to the lack of men. Then, on the third day came
the terrific storm which had prevented the rescuing party from
returning. Within a few hours after the screeching, howling gale had
first burst upon the island, the flimsy shacks, erected for summer
weather, had been completely wrecked; the tremendous seas had
swept far up the beach and had carried away the try-works and had
smashed and broached many of the casks of oil, and Mike and his
men had been compelled to perform Herculean labors to save
anything from the fury of the tempest.
By dint of incredible exertions they had managed to construct a
rude shelter from the wreckage and had saved the rest of the oil and
most of the supplies; but when the storm finally abated, the
drenched, tired and shivering men looked upon a scene of
desolation. The beach was littered with staved casks, boards, boxes
and ruined supplies. Masses of wave-driven kelp and flotsam were
piled high where the try-works had stood; the planks and canvas of
the hut were scattered about and not a sea elephant was in sight.
Mike shook his head as he surveyed the devastated camp.
“B’gorra!” he exclaimed. “Faith an’ ’tis the doin’s o’ the bo’sun burrd
—bad cess to him! An’ be the same token ’tis worrit Oi am over
Misther Potter an’ thim others. Foive days now, an’ divvil a soign av
thim. Beloike an’ they wuz caught in the big wind, ’tis dead they be.”
“Mister Potter, he put da grub an’ da water for week,” Manuel
reminded him.

You might also like