0% found this document useful (0 votes)
3 views

Instant data intensive apps with pandas how to manipulate visualize and analyze your data with pandas Hauck instant download

The document is a promotional overview of the book 'Instant Data Intensive Apps with pandas' by Trent Hauck, which focuses on using the pandas library for data manipulation, visualization, and analysis. It outlines the book's structure, including various topics such as working with files, slicing data, and integrating with other libraries like scikit-learn and Flask. Additionally, it provides links to other related programming books and resources available for download.

Uploaded by

jehudiliscu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Instant data intensive apps with pandas how to manipulate visualize and analyze your data with pandas Hauck instant download

The document is a promotional overview of the book 'Instant Data Intensive Apps with pandas' by Trent Hauck, which focuses on using the pandas library for data manipulation, visualization, and analysis. It outlines the book's structure, including various topics such as working with files, slicing data, and integrating with other libraries like scikit-learn and Flask. Additionally, it provides links to other related programming books and resources available for download.

Uploaded by

jehudiliscu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Instant data intensive apps with pandas how to

manipulate visualize and analyze your data with


pandas Hauck pdf download

https://ebookname.com/product/instant-data-intensive-apps-with-
pandas-how-to-manipulate-visualize-and-analyze-your-data-with-
pandas-hauck/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming Skills for Data Science Start Writing Code


to Wrangle Analyze and Visualize Data with R 1st
Edition Michael Freeman

https://ebookname.com/product/programming-skills-for-data-
science-start-writing-code-to-wrangle-analyze-and-visualize-data-
with-r-1st-edition-michael-freeman/

Programming Sound with Pure Data Make Your Apps Come


Alive with Dynamic Audio 1st Edition Tony Hillerson

https://ebookname.com/product/programming-sound-with-pure-data-
make-your-apps-come-alive-with-dynamic-audio-1st-edition-tony-
hillerson/

Mastering Pandas 1st Edition Anthony

https://ebookname.com/product/mastering-pandas-1st-edition-
anthony/

The Black Book of Training Secrets Enhanced Edition


Christian Thibaudeau

https://ebookname.com/product/the-black-book-of-training-secrets-
enhanced-edition-christian-thibaudeau/
Practicing Intelligence Providing Support to Combat
Operations 1st Edition Timothy Oliver

https://ebookname.com/product/practicing-intelligence-providing-
support-to-combat-operations-1st-edition-timothy-oliver/

Comprehensive Vascular and Endovascular Surgery Expert


Consult Online and Print 2nd Edition John W. Hallett
Jr. Md Facs

https://ebookname.com/product/comprehensive-vascular-and-
endovascular-surgery-expert-consult-online-and-print-2nd-edition-
john-w-hallett-jr-md-facs/

Los pueblos indi genas de Me xico y sus derechos una


breve mirada Moise■S Jaime Bailo■N Corres

https://ebookname.com/product/los-pueblos-indi-genas-de-me-xico-
y-sus-derechos-una-breve-mirada-moises-jaime-bailon-corres/

Culture and the Senses Kathryn Linn Geurts

https://ebookname.com/product/culture-and-the-senses-kathryn-
linn-geurts/

The Shaolin Monastery History Religion and the Chinese


Martial Arts 1° Edition Meir Shahar

https://ebookname.com/product/the-shaolin-monastery-history-
religion-and-the-chinese-martial-arts-1-edition-meir-shahar/
SSM Modern Physics 3e 3rd Edition Raymond A. Serway

https://ebookname.com/product/ssm-modern-physics-3e-3rd-edition-
raymond-a-serway/
Instant Data Intensive
Apps with pandas
How-to

Manipulate, visualize, and analyze your data with pandas

Trent Hauck

BIRMINGHAM - MUMBAI
Instant Data Intensive Apps with pandas
How-to

Copyright © 2013 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: May 2013

Production Reference: 1170513

Published by Packt Publishing Ltd.


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

ISBN 978-1-78216-558-3

www.packtpub.com
Credits

Author Project Coordinator


Trent Hauck Siddhant Shetty

Reviewer Proofreaders
Dan Mantyla Maria Gould
Amy Guest
Acquisition Editor
Akram Hussain Graphics
Ronak Dhruv
Commissioning Editor
Ameya Sawant Production Coordinator
Aditi Gajjar
Technical Editors
Dheera Meril Paul Cover Work
Vrinda Nitesh Bhosale Aditi Gajjar
Prachali Bhiwandker
Copy Editor
Alfida Paiva Cover Image
Sheetal Aute
About the Author

Trent Hauck is a graduate from the University of Kansas. He holds a Bachelor's in


Accounting and a Master's in Finance. Early in his career he worked in Finance and
Insurance, but has transitioned to Marketing and Analytics. Working with data and
finding tools for efficient use has been a theme throughout.

I'd like to thank my friends and family for their support and patience.
About the Reviewer

Dan Mantyla is a HPC Systems Programmer for Atipa Technologies and has been using
Python since 2009. As a utility infielder of all things, software development and with a BSCS
from the University of Kansas, Dan has done everything from contributing to open source
web frameworks to designing advanced cluster management architectures in Python. He
contributes to HPCwire.com and lives in a beautiful Lawrence, KS, home of Linux New
Media and birthplace of Python Django.
www.PacktPub.com

Support files, eBooks, discount offers and more


You might want to visit www.PacktPub.com for support files and downloads related to
your book.

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
service@packtpub.com 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

http://PacktLib.PacktPub.com

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

Why Subscribe?
ff Fully searchable across every book published by Packt
ff Copy and paste, print and bookmark content
ff On demand and accessible via 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 nine entirely free books. Simply use your login credentials for immediate access.
Table of Contents
Preface 1
Instant Data-intensive Apps with pandas How-to 5
Working with files (Simple) 5
Slicing pandas objects (Simple) 8
Subsetting data (Simple) 10
Working with dates (Medium) 12
Modifying data with functions (Simple) 14
Combining datasets (Medium) 18
Using indexes to manipulate objects (Medium) 20
Getting data from the Web (Simple) 23
Combining pandas with scikit-learn (Advanced) 25
Integrating pandas with statistics packages (Advanced) 28
Using Flask for the backend (Advanced) 30
Visualizing pandas objects (Advanced) 33
Reporting with pandas objects (Medium) 36
Preface
Python has long been considered one of the main "glue" languages for programmers and data
analysts due to its easy-to-learn syntax and a vast array of libraries to extend functionality. In
the last two or so years Python has become a language that isn't used for just the glue, but
the analysis itself. A big reason for that is pandas. This book covers pandas and other libraries
by example. The book is sectioned into recipes which start off with the basics, but through
progressively useful (and sometimes difficult) recipes the reader will get a good feel for pandas.

What this book covers


Working with files covers basic DataFrame creation as well as working with files. Very rarely is
data generated from within, so knowing how to work with files is important to get off the ground.

Slicing pandas objects explains how to slice the DataFrame. After following the first recipe a
DataFrame can be created, but the next step is understanding how to slice the DataFrame.
Thankfully, it isn't much different from a native Python array.

Subsetting data covers how to select just the data that is of interest, quite often during data
analysis. Cohort analysis is a good consequence of being able to subset data.

Working with dates will cover the beginning of how to carry out date manipulation. Date math
sucks. pandas makes it suck a little less.

Modifying data with functions teaches how to use functions to modify data. Not only is the
analyst often given too much data, but also the data often needs some work and applying
functions to that data can allow for easier use.

Combining datasets discusses how to take multiple datasets and combine them into one,
which is very similar to using SQL to join datasets.

Using indexes to manipulate objects demonstrates the use of indexes for data manipulation.
Index in pandas allows for easy manipulation of data. One way to think about Indexes is that if
data is made up of metrics and dimensions, indexes are the metadata used to describe those
metrics and dimensions.
Preface

Getting data from the Web explains how to get data from the Web. A hidden gem in
pandas is its ability to get data from all over. This brief recipe will show off this feature.

Combining pandas with scikit-learn explores how to integrate pandas with scikit-learn,
a library for Machine Learning. One of the great things about pandas is its ability to work
with other libraries in the PyData ecosystem.

Integrating pandas with statistics packages will discuss integration of pandas, using
StatsModels a module for classical statistics and econometric analysis.

Using Flask for the backend uses Flask. It's a micro framework that allows for quickly
building a web backend.

Visualizing pandas objects will discuss graphing and charting with pandas. Often large
amounts of data can't be understood just by looking at the raw numbers.

Reporting with pandas objects puts it all together. Using Flask as the backend, the
reader will build a basic reporting app to display a subset of a DataFrame.

What you need for this book


Obviously pandas is required, but in addition to pandas the following Python packages
are required:

ff Numpy
ff SciKit Learn
ff StatsModels
ff Flask
ff matplotlib
ff IPython (not technically required, but highly recommended)

ff Dependencies aren't mentioned; therefore, it is a good idea to use pip to


install these packages which will alert unmet dependencies.

Who this book is for


This book is for the people who interact with tabular datasets and who like Python, and
would like for Python to be a bigger part of how they interact with data. The readers should
be comfortable with Python, but no pandas experience is required.

2
Preface

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, database table names, folder names, filenames, file extensions, pathnames,
dummy URLs, user input, and Twitter handles are shown as follows: "Create an incredibly simple
DataFrame to start."

A block of code is set as follows:


> import pandas as pd #standard convention throughout the book
> import numpy as np
> my_df = pd.DataFrame([1,2,3])
> my_df
0
0 1
1 2
2 3

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


>import matplotlib.pyplot as plt
>plt.plot(close)

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 feedback@packtpub.com, and


mention the book title via 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.

3
Preface

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.

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.

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/submit-errata, 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 on our website, or
added to any list of existing errata, under the Errata section of that title. Any existing errata can
be viewed by selecting your title from http://www.packtpub.com/support.

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 copyright@packtpub.com 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 questions@packtpub.com if you are having a problem
with any aspect of the book, and we will do our best to address it.

4
Instant Data-intensive
Apps with pandas
How-to
Welcome to Instant Data Intensive Apps with pandas How-to. This book is a collection of
recipes with the intention of transforming the reader from being a novice with just a simple
idea of what pandas is, to a highly efficient user of the library. This book is not meant to be
a comprehensive look through all the nooks of pandas, but is meant to get the reader up
speed in the most common tasks.

Working with files (Simple)


In this recipe we'll introduce the pandas DataFrame by doing some quick exercises,
then move onto one of the most fundamental parts of data analysis; getting data in and
out of files.

Getting ready
Most of the rest of the book is working with data once it's in a pandas data structure, but this
recipe is about those structures themselves and getting data in and out of them. Open your
interpreter, preferably IPython.
Instant Data-intensive Apps with pandas How-to

How to do it...
1. Create an incredibly simple DataFrame to start with. A DataFrame can handle lists,
NumPy arrays, dicts of strings, and more.
> import pandas as pd
#standard convention throughout the book
> import numpy as np
> my_df = pd.DataFrame([1,2,3])
> my_df
0
0 1
1 2
2 3

2. The first example is too simple, and isn't useful. Add some column headers and index
for more information about the DataFrame.
> cols = ['A', 'B']
> idx = pd.Index(list('name'), name='a')
> data = np.random.normal(10, 1, (4, 2))
> df = pd.DataFrame(data, columns=cols, index=idx)
df
A B
a
n 9.945858 10.607128
a 10.742073 8.968044
m 10.178861 7.293450
e 10.251922 10.657038

#a single column is a series


> df.A
a
n 9.945858
a 10.742073
m 10.178861
e 10.251922
Create a Panel by passing a dictionary of DataFrames to the
constructor.
# multiple DataFrames is a panel
> pan = pd.Panel({'df1': df, 'df2': df})
> pan

6
Instant Data-intensive Apps with pandas How-to
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: df1 to df2
Major_axis axis: n to e
Minor_axis axis: A to B

3. There are many ways to do I/O with pandas; in this step we will write the DataFrame
out to several mediums.
#write df to different file types
> df.to_csv('df.csv')
> df.to_latex('df.tex') #useful with Pweave
> df.to_excel('df.xlsx') #requires extra packages
> df.to_html('df.html')
> df.to_string()
' A B\na \na 9.945858
10.607128\nb 10.742073 8.968044\nc 10.178861 7.293450\nd
10.251922 10.657038'

#read df from the files, output methods aren't symmetric


#often there's an intermediate step

> pd.read_csv('df.csv')

#back and forth with json


#json isn't officially supported, the reasons why are beyond #the
scope of this book
> with open('df.json', 'w') as f:
json.dump(df.to_dict(), f)

> with open('df.json') as f:


df_json = json.load(f)

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.

7
Instant Data-intensive Apps with pandas How-to

How it works...
Most of the file input and output in pandas is the orchestration behind the scenes of
formatting the value outputs, and then writing those values to a file. There are many
options for formatting file output. The to_csv method takes many parameters. Some
of the more common parameters are as follows:

ff sep: It specifies the value to separate with, in the output file


ff index: It is a Boolean that decides whether or not to print the index
ff na_rep: It specifies what to substitute for the na values

The following snippet writes the DataFrame df and writes it to a file called file.tsv,
and it's formatted according to the parameters passed to the method.
> df.to_csv('file.tsv', sep='\t', index=False, na_rep='NULL')

There's more...
In addition to standard file input and output functionalities, pandas has several built-in niceties.

Parsing dates at file read time


Using Panda's sophisticated date parser, a CSV can read and parse dates at the same time,
as shown in the following command line:
> df = pd.read_csv('dates.csv', date_parser=True, parse_dates='YYYY-MM-
DD', index_col=0)

Besides the parsing capabilities, pandas also has a very handy date_range function,
which returns a range of dates determined by the inputs. For example, it's very easy to
get the months of 2012 in a series. This is shown in the following command line:
> pd.date_range('2012-01-01', '2012-12-31', freq='M')

Accessing data from a public source


pandas can also read CSV data from the Web, assuming http://www.example.com/
data.csv is the URL. Take a look at the following example:

> df = pd.read_csv(url)

Slicing pandas objects (Simple)


In this recipe we'll walk through some basic functionalities about slicing pandas objects. If
you're familiar with array slicing, this will be very familiar to you, but with a few idiosyncrasies
for pandas.

8
Instant Data-intensive Apps with pandas How-to

Getting ready
Open up your interpreter, and execute the following steps:

How to do it...
1. Create a simple DataFrame to explore the different slicing abilities of pandas.
> dim = (10, 3)
> df = pd.DataFrame(np.random.normal(0, 1, dim), columns ['one',
'two', 'three'])

2. Select the first two rows of the column named 'one'.


> df['one'][:2]
0 -0.492156
1 -0.476418
Name: one

3. Pass an array of column names instead of 'one'.


> df[['one', 'two']][:2]
one two
0 -0.492156 1.978798
-0.476418 -0.225360

4. Use a negative index to navigate backwards through the DataFrame.


> df[['one', 'two']][-3:-2]
one two
7 -0.392156 1.478198

5. Select every fifth row from the DataFrame df.


> df[::5]
one two three
0 0.317379 -0.551568 -1.617768
5 -0.171340 2.025818 0.206053

6. Use the head and tail functions to easily select the top and bottom of the
DataFrame.
> df.head(2)
one two
0 -0.492156 1.978798
1 -0.476418 -0.225360

9
Instant Data-intensive Apps with pandas How-to

How it works...
At some level, pandas objects behave similar to NumPy arrays; they are after all abstractions
built on top of them. However, because we have more metadata about the data structures we
can use that to our advantage.

After the initial pandas object is created, simple slicing occurs according to the
following structure:
> df[column names][rows]

Here column names is a string (or an array, if multiple columns) and rows is the number of
rows that we wish to use.

There's more...
The methods that have already been described are very useful at a higher level, but there are
more granular operations available.

Direct index access


The .ix command is an advanced method for selecting and slicing a DataFrame. Taking the
sample from the preceding example, df.ix[1:3 ,[ 'one', 'two']] = 10 will not only
select the specified subset of the data, but also set its value equal to 10. The .xs command
has a more explicit interface for working with indexes.

Resetting the index


Often, the index of the DataFrame becomes out of alignment when slicing data. In pandas, the
easiest way to reset an index is with the reset_index() method of the DataFrame object.

Subsetting data (Simple)


In this recipe we'll select parts of a DataFrame based on elements within the DataFrame. For
example, select data only if it's greater than zero.

Getting ready
Open up your interpreter and follow along with the interpreter's session in the following How to
do it… section.

10
Instant Data-intensive Apps with pandas How-to

How to do it...
1. Create a sample DataFrame df to manipulate.
> d = {'Cost': np.random.normal(100, 5, 100),
'Profit': np.random.normal(50, 5, 100),
'CatA': np.random.choice(['a', 'b', 'c'], 100),
'CatB': np.random.choice(['e', 'f', 'g'], 100)}

> df = pd.DataFrame(d)

2. Pass a Boolean value to the DataFrame to select only those rows that evaluate to True.
> df[df.CatA == 'a'][:5]
CatA CatB Cost Profit
0 a g 102.716045 48.585048
1 a g 103.342873 44.285223
3 a f 100.563783 52.609880
4 a f 92.057118 53.030021
10 a f 97.494169 44.849129

> mask = np.logical_and(df.CatA=='a', df.CatB=='e')


> df[mask][:5]
CatA CatB Cost Profit
15 a e 103.532647 44.625927
20 a e 101.780083 48.415357
57 a e 95.795958 46.033187
76 a e 96.831145 53.876999
77 a e 100.991794 44.308626

> a_e = ['a', 'e']


> CatA_a_e = df[df.CatA.isin(a_e)]
> only_a_e = CatA_a_e[CatA_a_e.CatB.isin(a_e)]
> only_a_e[:5]
CatA CatB Cost Profit
15 a e 103.532647 44.625927
20 a e 101.780083 48.415357
57 a e 95.795958 46.033187
76 a e 96.831145 53.876999
77 a e 100.991794 44.308626

11
Instant Data-intensive Apps with pandas How-to

How it works...
Subsetting is an integral part of data analysis, and is very simple to do in pandas. A nice
pattern for creating subsets is to create mask arrays, which are arrays of Booleans, and
then passing those into the DataFrame. For example, executing df[df.CatA.isin(a_e)]
in the interpreter will return an array of the same length as df.CatA.

There's more...
There are more powerful pandas functions that make selecting subsets of DataFrames
more concise.

The where and mask commands


In addition to masking data based on arrays, pandas contains many helper functions to
subset and assign values to data. The two main ones are df.where() and df.mask(),
which are complements. The df.CatA.where(df.CatA == 'a') function doesn't
automatically remove data like in the previous examples; it creates a copy of df.CatA with
NaN in places where df.CatA doesn't equals to 'a'.

Substituting with the where command


Taking the where command one step further, it's easy to replace the NaN element in one
step. For example, df.CatA.where(df.CatA == 'a', 'e') will substitute NaN where
df.CatA is equal to 'a'; however, because there is the second argument, the NaN will be
replaced by 'e'.

Working with dates (Medium)


In this recipe we'll talk about working with dates in pandas. Because pandas was initially
written with financial time series, it has a lot of out of the box date functionalities.

Getting ready
Open up your interpreter and follow the command progression in the following section.
Difficult financial analysis was the mother of pandas creation; therefore, it has many efficient
and easy ways for dealing with dates.

How to do it...
1. Let's examine the date_range functionality within pandas.
> Y2K = pd.date_range('2000-01-01', '2000-12-31')
> Y2K

12
Instant Data-intensive Apps with pandas How-to
class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 00:00:00, ..., 2000-12-31 00:00:00]
Length: 366, Freq: D, Timezone: None

#it is very easy to create date range of a different frequency


> Y2K_hourly = pd.date_range('2000-01-01', '2000-12-31', freq='H')
> Y2K_hourly
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 00:00:00, ..., 2000-12-31 00:00:00]
Length: 8761, Freq: H, Timezone: None

2. Create a time series and slice it by passing a range of dates to Series.


> Y2K_temp = pd.Series(np.random.normal(75, 10, len(Y2K)),
index=Y2K)
> Y2K_temp.head()
2000-01-01 77.425233
2000-01-02 67.949946
2000-01-03 74.079854
2000-01-04 83.048726
2000-01-05 88.435598
Freq: D

> Y2K_temp['2000-01-01':'2000-01-02']
2000-01-01 77.425233
2000-01-02 67.949946
Freq: D

> from datetime import date


> Y2K_temp[date(2000, 1, 1):date(2000, 1, 2)]
2000-01-01 77.425233
2000-01-02 67.949946
Freq: D

#pandas has functionality to move into and out-of date scopes


> Y2K_temp.resample('H', fill_method='pad')[:1]
2000-01-01 01:00:00 77.425233
Freq: H

13
Instant Data-intensive Apps with pandas How-to

How it works...
The date_range function is defined by dates and frequencies. See the following section for
the various frequency designations. The easiest way is to define a start date, end date, and
frequency, but there are other ways as well. You can also change the frequency, or resample
to a smaller or larger time interval.

There's more...
pandas adds a lot more functionalities to handle dates. These are mostly convenient methods
because working with dates is a necessary evil of data analysis.

Alternative date range specification


Time series in pandas don't have to be defined by a start and end date. In pandas, it is
possible to represent the time of the Series as an interval of dates with a common period
between data points. For example, if we want to create a Series just like Y2K, we can do
so as follows:
pd.date_range(start='2012-01-01', periods=366, freq='D')

Upsampling and downsampling Series


pandas offers the ability to move up and down the granularity of a time series. For example,
given a Series of random numbers s for all the days in 2012, calculating the sum for each
month is done by the following formula:

s.resample('M', how='sum')

In the preceding example, the 'M' variable specifies that we're upsampling to month.
Downsampling is also done in a similar way; however, pandas provides functionalities for
handling the disaggregation in a convenient way.

Modifying data with functions (Simple)


In this recipe we'll walk through the process of applying a function to a DataFrame. This is
a simple but very important part of data analysis. Rarely, if ever, will a data in raw form be
sufficient for data analysis. Often, that data needs to be transformed into some other form,
and to do that you'll need to apply functions to pandas objects.

Getting ready
Open up your interpreter, and type the following commands successively.

14
Instant Data-intensive Apps with pandas How-to

How to do it...
1. Create a simple Series of simulated open and close for a year.
> data = {'Open': np.random.normal(100, 5, 366),
'Close': np.random.normal(100, 5, 366)}

> df = pd.DataFrame(data)

> df
<class 'pandas.core.frame.DataFrame'>
Int64Index: 366 entries, 0 to 365
Data columns:
Close 366 non-null values
Open 366 non-null values
dtypes: float64(2)

2. Apply element-wise functions.


> df.apply(np.mean, axis=1).head(3)
0 103.313391
1 99.668034
2 97.875755

#passing a lambda is a common pattern


> df.apply(lambda x: (x['Open'] - x['Close']), axis=1).head(3)
0 6.519618
1 8.407379
2 16.838463

#define a more complex function


> def percent_change(x):
return (x['Open'] - x['Close']) / x['Open']
> df.apply(percent_change, axis=1).head(3)
0 0.061175
1 0.080940
2 0.158413

#change axis, axis = 0 is default

15
Instant Data-intensive Apps with pandas How-to
> df.apply(np.mean, axis=0)
Close 99.739967
Open 99.631989

3. Define a standalone function that takes two arguments. One is the element itself,
and another argument.
> def greater_than_x(element, x):
return element > x

> df.Open.apply(greater_than_x, args=(100,)).head(3)


0 False
1 True
2 False
Name: Open

#This can be used as in conjunction with subset capabilities


> mask = df.Open.apply(greater_than_x, args=(100,))

> df.Open[mask].head()
1 100.713672
3 105.492173
4 100.171148
6 104.810547
7 110.539181
Name: Open

#It's also possible to do a rolling apply, this applys #aggregate


functions over a certain number of rows
#For instance we can get the five day moving average
> pd.rolling_apply(df.Close, 5, np.mean)

#There are actually a several built-in rolling functions


> pd.rolling_corr(df.Close, df.Open, 5)[:5]
0 NaN
1 NaN
2 NaN
3 NaN
4 0.137234 #why are the first 4 NaN

16
Exploring the Variety of Random
Documents with Different Content
of the hour, which were never to be realised, was a projected visit to
the Holy Land. She would so like to see the holy places!
"The wildest scheme!" young Del Vasto pronounced it, when a
rumour of it reached him at Rome. He lost no time in hastening to
his beloved friend, to dissuade her from what she had perhaps never
seriously contemplated, and to induce her to be content with the
Eternal City. And when she reached it, she was received with almost
public honours—so proud was Italy of its "divine Vittoria Colonna!"
Here she found a circle of the most eminent men in Italy, hopefully
awaiting the issue of Cardinal Contarini's conciliatory mission to the
German Reformers; and it was trusted that, by wise concessions on
the part of Rome, a fearful schism might be avoided. But when did
Rome ever make wise concessions?
It was at this time that the friendship commenced between Vittoria
and Michael Angelo, which was equally honourable to both; and we
have his own word for it, that through her he was made a devout
Christian. It was the crowning beauty of her life.
Meanwhile Giulia was the prey of intense melancholy at Fondi. It
expressed itself in joyless looks, in mournful tones, in neglected
dress, in small austerities, in rising at out-of-the-way hours to tell
her rosary, &c.
Her ladies united in declaring that she must be ill, and that the
marsh miasma was answerable for it. So then Bar Hhasdai was sent
for; and he advised change of air and quantum sufficit of generous
red wine well spiced. She acquiesced in both prescriptions; and then
indulged in a little doctors' gossip, that most healing balm. They
talked over the Cardinal's death, and Bar Hhasdai said that, even if
he had been sooner sent for, he did not believe he could have saved
him.
"One cardinal the less, one saint the more," said Giulia.
Bar Hhasdai looked sceptical. "Was he of the stuff that saints are
made of?" said he.
"He was very generally liked," said Giulia.
"And so long as thou doest good unto thyself, men will speak well of
thee," said the Jew, equivocally.
So she returned to her old quarters at Naples, where she had the
satisfaction of hearing from Valdés, who immediately waited on her,
that Ochino was again preaching with great acceptance. She had
tried ascetic mortifications, on a small scale, without any beneficial
result; and she now, with a heart aching for a better life, and sick of
the world's pleasures, which, after all, she had never much indulged
in, resolved to prove whether enduring comfort might not be derived
from the cross of Christ.
CHAPTER XVIII.
A BETTER LIFE.
You may have seen an old print of Titus's Arch, in the foreground of
which is an Italian lady of quality, with hoop, lappets, and fan,
sailing to church, attended by her gentleman-usher. A stately man-
servant in advance clears the way, two ladies-in-waiting follow their
mistress at a respectful distance, and two or three more menials
close the procession.
Something in this style did Giulia go to the cathedral. As she was
returning from it one evening, accompanied by Valdés, her heart
was full, and, after one or two ineffectual beginnings she said—[15]
[15] Vide "Alfabeto Christiano."
"I have so much confidence in our friendship, Signor Valdés, that I
feel as if I could speak to you on some subjects even more freely
than to a confessor. If you are not pre-engaged, therefore, I would
gladly tell you what is on my mind. Do I importune you?"
"On the contrary, Signora," said Valdés, "I am honoured by your
commands, and you well know there is no one I love better to
serve."
"A truce, then, with compliments of every kind. I want to open to
you my whole heart, for I am sure you will pity me. I am a prey to
such constant dissatisfaction with myself and with everything around
me, as cannot be described. I neither know what I wish, nor with
what I should be contented. Hence, I cannot conceive anything that
could be offered me capable of appeasing this inquietude and
removing my confusion of mind. Many years have I felt thus: and of
late you have given me reason to hope that if I would give ear to the
preaching of Ochino I should be tranquillised. Alas, I find it quite
otherwise! And though I admit that the fault may be mine rather
than his, yet the disappointment is so bitter, that tears frequently
come into my eyes through not knowing what to do with myself, nor
what to lean upon."
Saying which, her tone was so sad, and she looked so troubled, that
the humane Valdés was filled with compassion.
"Say freely, Signora," said he, "whatever you wish to ask of me; and
be assured that I will always expend in your service all that I know
and am able to do."
"Tell me, then," said Giulia, "from what cause you believe this state
of mind to spring, and how, if possible, it can be remedied, or
whether it must be borne."
"You must first make me one promise," said Valdés.
"What can that be?" inquired the Duchess.
"If I show you the way by which you may be relieved from your
disquietude, you must promise to walk in it."
"Of course. Gladly!"
"Be very attentive, then, Signora, to what I am about to say. You
know it is written that man is made 'in the image and likeness of
God.' And you will also remember that St. Paul counsels the
Corinthians to put off the old man with his deeds, that is, the sinful
nature we have all inherited since the fall, and be clothed with the
new man, who is created 'in the image and likeness of God.' From
this it appears, that in such a degree as man retains in himself the
image and likeness of God, in the same degree he apprehends and
appreciates spiritual things in a spiritual life and conversation.
Recognise this, and you will all at once perceive whence your
disorder and disquietude of mind arise; because you will see that
your soul is striving for restitution to the image of God, of which at
present it is deprived. The remedy is in your own hands."
"In my hands?"
"Yes! Because as soon as you determine to renew and restore within
yourself the image and likeness of God, you will find peace, quiet,
and repose."
Giulia drew a deep breath, and then said—
"How must I do this?"
"By withdrawing your affections from vain and transitory things, and
fixing them on those which are spiritual and eternal. Your spirit thus
finding its proper aliment, will always be content and cheerful, and
here in this present life will begin to taste of that felicity which it
expects to enjoy for ever in the life eternal. To this happiness only
the real Christian can attain."
"As for that," said the Duchess, "I know many persons who have as
much, and perhaps more, cancelled the image of God than I have,
who are yet perfectly content and happy."
"Such persons," returned Valdés, "have low and vulgar minds, and
can therefore suffice themselves with mean and frivolous objects
that could never satisfy a refined and generous nature like yours.... I
am not at all sorry that you should be troubled in the way you have
described, because it shows that the preaching of the Gospel is
producing its first effect on you.... There is nothing in this world that
could give me so much pleasure as to see you walking in the path of
life, for I hold it for certain that, once in complete union with God,
you would outstrip many who are now saints in heaven."
"I desire to do so," said she, softly.
"Then why don't you do what you desire?" rejoined Valdés.
"Because I don't know how."
"Force, force, Signora! force is the one thing wanting. 'The kingdom
of heaven suffereth violence, and the violent take it by force.'"
"Lead me by the hand, then," said she, "instructing me in those
footsteps by which I believe you have walked."
"You want me," said Valdés, "to show you some royal and ladylike
road by which you may get to God without turning away from the
world. But, lady, no such compromise can be made. Have you ever
crossed a running stream?"
"Yes, many times."
"Do you not remember how your head swam if you looked at the
flowing water, but how steady it was if you fixed your eyes on the
opposite shore? Thus, with God and the world, endeavour to keep
the view of your soul fixed and nailed with Christ on the cross. And if
at any time, through want of care, your eyes are diverted to the
things of this world, return, return, Signora, as quickly as possible,
to fix them on Christ crucified; and all will be well. You know the
human heart is naturally inclined to love. It must either love God and
all things for God, or it must love itself and all things for itself. He
who loves God, performs everything he does for Him. And thus, if he
loves anything besides God, he loves it for the sake of God, and
because God wills it so. And then his good works please and are
acceptable to God, because they spring from love. Agreeable to this
is what St. Augustine says—'Good works follow in them who are
already justified, and do not go before in him who has to be
justified.' You know how you yourself estimate what a person does
in your affairs when you know you owe not his good services to the
affection he bears you, but to some other motive."
This dialogue, which had been begun in the open air, was now being
carried on in the Duchess's parlour. She sat in a high-backed, richly
carved chair, looking out through the balconied window, on the bay
of Naples, with streaks of summer lightning now and then illumining
the sky, and the lurid fires of Vesuvius glowing in the distance.
Valdés sat on a stool a little apart.
"Since you wish me," said she, after a pause, "to make the love of
God my prime motive, and, next to it, the love of my neighbour,—
well then, I will do so!—but mention, if it please you, some rule by
which I may know and understand what it is I ought to do; because
I wish to give myself up to the love of God, even so much so as to
deprive myself of your favour, and that of a hundred others like
you."
"No, Signora, no! you can never do that!" said Valdés, fervently: and
he then sketched out for her the outline of a Christian life, not
circumscribed within slavish bounds, but capable of adaptation to
time and place, sex and degree, based only on the immutable
principle of loving God above and in all things, and one's neighbour
even as one's self. It was a memorable evening for Giulia. Her
cheeks were wet with tears, but they were the sweetest she had
ever shed. They took no note of time, but prolonged the interview
till night.
When they parted, she said to him:
"I shall never forget this conversation!"
"And I," said he, deeply moved, "shall remember it always."
"Oh, that I could preserve every word you have spoken! Do you
think you could commit the substance to writing?"
"Undoubtedly, if you wish it."
"I do wish it, most earnestly. And pray for me, pray for me, dear
friend, that your words may not only sink into my heart, but take
root in it, and bring forth fruit abundantly."
"I will, indeed, Signora; but, above all, fail not to pray for yourself,
that the love of God may abound in you yet more and more."
"Never knew I till now what that love was! I have heard tell a
thousand times of this going out of a person's self to enter into God,
but never, in all I have heard, was it made comprehensible."
"You are so much the more under obligation to love God, since He
has preserved you so long in this world as to come to know this
which till now you have not understood."
"You are right. May it please God that I know how to profit by it."
She gave him her hand. He kissed it with the utmost reverence:
then, raising his eyes heavenwards, uttered a short, fervent prayer
for her confirmation in the knowledge and love of God.
When he was gone, she covered her eyes with her hand, and tears
slowly trickled down her cheeks. Almost unconsciously, she sank on
her knees and murmured——
"O, my God! teach me to be what Thou wouldst have me to be, and
then enable me to do what Thou wouldst have me to do! Form in
me Thine own image and likeness, for Christ's sake!"
A strange calm and sweet peace took possession of her soul.
When Valdés presented himself to her, a few days afterwards, he
brought her his manuscript version of the substance of their
dialogue, written in his native Spanish, which was nearly as familiar
to her as Italian, seeing that it was continually spoken by Vittoria
Colonna and others of her familiar acquaintance. The faithfulness
with which he had recalled the vivacity of her rejoinders showed how
deeply they had interested him, and if his own speeches were less
closely reported, it was chiefly because he had taken the opportunity
of extending them even at the price of weakening their spirit.
"Here," said he, "you have what you required of me; and I have
called it the Christian Alphabet, because, in fact, it contains but the
A B C of Christian doctrine. Believe in nothing I have here set down
that you cannot bring to the test of Scripture. And do not content
yourself with this Alphabet, or with any mere writings of men, but
drink of the pure water of life at its source. May Christ become the
peaceful possessor of your heart, in such a manner as that He may
absolutely and without contradiction rule and regulate all your
purposes. When this is the case, you will not feel the want of
anything whatsoever in this life to give you contentment and
repose."
She took the book with solemnity, and promised compliance with his
wishes. This singular little work, of which, till lately, it was not known
that there was a copy extant, does not profess to be more than what
Valdés called it, and confines itself to inculcating the formation of the
Divine image in the soul, if haply it might find Him, without
attempting to attack the prevailing corruptions of the Church. In
fact, this remarkable layman, who set so many Reformers forward
on the path of martyrdom, did so by inculcating a few great truths,
rather than by pulling down strongholds of error; and a certain class
of his disciples eventually brought discredit on him by veiling
Reformed opinions under the punctilious observance of Romish
practices. But not of these temporising spirits were Carnesecchi,
Flaminio, or Vergerio; all of whom were of the school of Valdés.
CHAPTER XIX.
REST AND PEACE.
When the structure is built, the scaffolding is removed: when we are
raised up to Christ, our earthly props are often knocked away.
Ochino was soon to leave Naples—Valdés was soon to leave this
earthly world. For a little while the Church had rest: and then burst
out a furious, fiery persecution. Its burning annals have no place in
my story; but I will annex a chapter about it as an Appendix, for
those who will not or cannot refer to the original sources.
An advance had taken place in Ochino's opinions, which, for a time,
was felt rather than understood by his hearers. He appealed directly
to the Scriptures in support of his doctrine, and bade them search
for themselves. In spite of his boldness, he not only was allowed to
continue to preach in the Cathedral, but, in a chapter held at Naples
in 1541, was re-elected General of the Capuchins.
His departure from the Church of Rome was detected, however, by
the jealous eye of Cardinal Pole, who wrote to Vittoria Colonna,
urging her to beware of his influence, and even exacting from her a
promise, which no woman of independent spirit would have given,
that she would not read any letter addressed to her by Ochino,
without consulting him or Cardinal Cervini. Vittoria gave this
promise, and afterwards redeemed it by transmitting to Cardinal
Cervini, not one letter, but a packet of letters written to her by
Ochino; observing on them, in an accompanying note, "I am grieved
to see that the more he attempts to excuse himself, he condemns
himself the more; and the more he believes he shall save others
from shipwreck, the more he exposes himself to the deluge; being
out of the ark which alone can save."
Vittoria was at Rome, the head-quarters of intolerance, attending Fra
Ambrogio's lectures in the church of San Silvestro, and sending her
servant, after the sermon, to Michael Angelo, saying, "Tell him that I
and Messer Lattanzio are here in this cool chapel, that the church is
shut and very pleasant, and ask him if he will come and spend the
morning with us." And when he came, their talk was not of polemics,
but of painting, and of her building a convent on the slope of Monte
Cavallo.
Vittoria, having put her hand to the plough, had drawn back; but
Giulia had chosen the better part, and has attained the honour of
being stigmatised in Romish records as "suspected of heretical
pravity."
Oh! how she wept when Valdés died! They were tears of sweet and
pure affection, unmixed with bitterness or gloomy foreboding, for he
had been called, at the second watch, to his rest: and she had now
a good assurance of following in the same luminous track, upheld by
the same right hand, straight up to heaven, without the intervention
of a fearful purgatory.
He was called away in the strength of his manhood, for he was little
more than forty, and his twin brother is lost sight of about the same
time. Lovely in their lives, in death they were not long divided.
Peaceful, natural decline removed them from the persecutions that
awaited their followers.
It is not hard to divine his last admonitions to Giulia. "Search the
Scriptures, for in them we know that we have eternal life. Pray, dear
Signora! pray! As our Lord prayed on the mount, the fashion of His
countenance was altered, and His raiment became white and
glistening! Doubtless, whenever we pray, the expression of our
countenance is altered in the sight of God, if not of man; and our
raiment, the righteousness of Christ, becomes white and glistening.
Oh, what an incentive to prayer! St. Matthew and St. Luke, you will
find, in narrating the transfiguration, do not give us the preface
—'and as he prayed.' But how important an addition it is! What a
blessing that prayer drew down! It drew prophets and saints from
heaven!"
"Valdés, dear friend! Would that my prayers might hereafter draw
you down from heaven to comfort me! Yet no; I recall the selfish
wish. Rather let me fancy you calling, 'Come up hither!'"
"Fancy our Lord so calling you, dear Signora, and it will be mere
fancy no longer. All my teaching will have been in vain, if you covet
human rather than divine sympathy and help."
"But you have been to me as a brother."
"There is a Friend that sticketh closer than a brother, Signora. Come,
give me a text, ere you leave me, to dwell upon when you are
gone."
"'Ye shall go out with joy, and be led forth with peace.'"
"God grant it! And here is one for you, whose time has not yet come
to be led forth. 'Behold! I have refined thee, but not with silver'—
(not in the same way, that is; not with mere physical heat)—'I have
chosen thee in the furnace of affliction.' See! there is something that
escapes us at first. God not only says He has tested us, but that He
has chosen us. O, blessed to be the chosen of the Lord——"
"Valdés, I seek Him, but I know not that I have yet found Him——"
"Signora! 'let the heart of them rejoice that seek the Lord.'"
While masses were being sung and said for the soul of Cardinal
Ippolito, the spirit of Valdés departed without a sigh. "For so He
giveth His beloved sleep." But were Giulia's affections, which had
been gradually refining, then left without a human object? No. By
the will of his paternal grandfather, her nephew, Vespasiano, the
little Duke of Sabionetta, came into her charge; and the education of
the dear little boy, now eight years old, became her care. She
procured the best and most enlightened tutors for him, in Tuscan,
Latin, and Greek; and despatched an envoy to Charles the Fifth, to
secure for him the investiture of the state of Lombardy, and to
supersede its administrators by Don Ferrante and Cardinal Ercole
Gonzaga.
This young boy was trained up by her in the paths of virtue and
godliness; and lovingly did he repay her pains. He grew up a fine
character, distinguished for liberality and intelligence; and to him the
Jews owed the licence for their printing press at Sabionetta. When
he died, in 1591, the line became extinct.
Besides superintending Vespasiano's education, the Duchess devoted
herself to visiting the sick in the hospitals, and relieving the poor
with her own hands. She shunned the company of the idle and
frivolous, and cultivated the friendship of the wise and good. She
lived to a ripe old age, shining more and more unto the perfect day
—a light in a dark place, during an age of gross corruption—
unsullied by the breath of slander, and respected, in spite of her
averred 'heretical pravity,' by the Romish Church.
The faithful old maggior-domo, Perez, wrote thus to Vespasiano, on
the 19th of April, 1566:

"It appears to me that I should fail in my duty, as a servant for


twenty-one years together, towards the deserving memory of
the illustrious lady, my Lady Donna Giulia di Gonzaga, your
aunt, if I did not offer to condole with your Excellency on her
death.
... "Her illustrious ladyship died, as you will have heard by letter
from Magnifico Modignano, and from M. Federigo Zanichelli to-
day, between twenty-one and twenty-two o'clock. She made an
end conforming with her most holy life, continuing sensible to
the moment when her sainted spirit left the body. Her will has
been opened, and you will have learnt from the before-
mentioned Modignano and Zanichelli, that your Excellency is left
absolute heir of her property, deducting certain legacies; the will
being very different from one executed seven years ago."
To the aforesaid Perez she left an annuity of a hundred ducats: to
Caterina, her maid, two hundred ducats down, and a bed and
bedding. To Petrillo, whom she had brought up in her house, a
thousand ducats; or, in case of his death before he were of age, half
that sum to his father and mother. To Metello, her page, a hundred
ducats down. To the brother of her former maid, Caterina Rosso,
and to his two children, a hundred ducats each, in remembrance of
her services. To her chaplain, twenty ducats. To Madonna Antonia,
her lady's-maid, twenty ducats and her salary. To two little girls
assisting in the kitchen, ten ducats each, besides their wages. To all
the house-servants, their expenses for a month.
Also, remembrances to the nuns of Santa Clara, and to certain
officers of the Hospital for Incurables.
Also marriage portions to sundry young women, and legacies to her
physicians.
Also legacies to four hospitals.
This remarkable entry was made——
"I leave Cynthia, my slave, to the said Vespasiano my heir, whom I
direct to take her to his state of Lombardy; and, when he has come
to the truth of what I wished to know from her, to give her in
marriage in that province, with two hundred ducats currency as
dowry, and to make her free and set her at liberty."
And, on re-consideration, towards the close of the will,—after leaving
a legacy to her undutiful daughter-in-law, and to her sister, a nun,
——
"If ever any person be found who may have given me offence in any
manner whatsoever, I freely pardon them, and beg my heir not to
bear any resentment. I also order and bind my said heir that he use
no constraint or severity towards the said Cynthia;—nor am I careful
that he should learn from her what I said before that I wished to
know; but that he shall make her free and set her at liberty, and give
her in marriage in the province of Lombardy, as I before said."
If looks could kill, would not the stubborn, impenetrable Cynthia
have been annihilated by the glances that were given her by the rest
of the Duchess's women, when this testamentary disposition
transpired? Had they the concentrated power of burning-glasses, she
would have borne them just as stoutly. All her life she had been
sinning and inly repenting; but, to draw from her one word she did
not choose to speak—no! that they should not! She, an
Abencerrage, to be treated like a slave? She had no feelings in
common with her captors: she hated their race, and despised their
creed. She only made an exception in favour of the Duchess; but the
Duchess did not understand her: nobody understood her. Oh! how
hackneyed a complaint it is, that we are not understood!
So, although Cynthia had shed sincere tears for her mistress, she felt
a gloomy glory, when she heard the first clause relating to herself, in
thinking that the more the young Duke insisted on her telling, the
more she would never mind. But when she found her gentle mistress
had retracted that command, and left her mentally and bodily at
liberty—she stole away to a solitary place, and there shed big tears,
beating her breast, and saying,
"O Leila, Leila! You loved me!—and indeed I loved you!"
APPENDIX.

My story is ended—but, as it is based on Truth, I hope few who have


read the foregoing pages with any pleasure, will be without some
interest in the subsequent progress of the Italian Reformation.
Stifled in its infancy, it is now re-awakening into life; and though it
as yet only numbers its open converts by hundreds, yet, where the
Bible is now freely read, it cannot be but that Truth, which is great,
shall eventually prevail.
The following sketch, chiefly abridged from McCrie may be
acceptable to those who cannot refer to his History of the
Reformation in Italy. I have, however, likewise drawn from other
sources.
It was in 1542 that the court of Rome first became seriously alarmed
at the progress of the new opinions in Italy. Cardinal Caraffa, who
afterwards became Pope Paul the Fourth, laid before the sacred
college the discoveries he had made of their spread in Naples and
many other parts. It was resolved to proceed against some of the
leaders, especially Ochino and Peter Martyr Vermigli. Ochino,
learning that his death was determined on at Rome, hastily fled to
Ferrara, whence, being assisted by the good Duchess Renée, he
escaped the hands of the armed men despatched to apprehend him,
and reached Geneva in safety.
This flight was considered very cowardly by the resolute disciples he
had left behind; and, indeed, Ochino's story would read much better
if he had remained to share their fate, for there is a great falling off
in his subsequent history.
As for Martyr, who had parted with him at Florence, he took refuge
in Zurich, whence he wrote back to those whom he had left to
weather the storm, advising them by all means to stand by the
sinking ship! Seeing the wolf coming, he and Ochino left the sheep,
and fled; no wonder that the wolf scattered the sheep.
The result was this. Many of Ochino's friends were apprehended,
and some of them driven to recant: and eighteen monks of Peter
Martyr's monastery were thrown into prison. Before the year was
out, eighteen more of them escaped to Switzerland. Yet the little
church that was in Lucca kept its lamp burning twelve more years.
Celio Curio was another leading Reformer. Receiving private
information that he had better consult his safety, he sought refuge in
Lausanne. A few months afterwards, he stole back to fetch his
beloved wife and children; but was tracked by the familiars of the
Inquisition. He was dining at an inn, when a captain of the Papal
Band entered, and commanded him to surrender. Celio rose from
table, the carving-knife still in his hand; the captain involuntarily
drew back—seeing which, Celio, still grasping the knife, and
assuming a look of great determination, walked deliberately out of
the room, passed through the armed men at the door, took his horse
from the stable, and made off.
The Inquisition had been introduced into Italy at its first
establishment in the twelfth century, but was so repugnant to the
free states, that it was confined to the Order of St. Francis. Bishops
might take part with the inquisitors in the examination of heretics,
but had no power to inflict punishments. In 1543, however, Paul the
Third granted the title and rights of inquisitors to six cardinals, with
full power to apprehend and imprison suspected persons of
whatever rank: and the operations of this court gradually extended
over Italy, in spite of great resistance. This was decisive of the
unfortunate issue of the movements in favour of religious reform.
Numbers of Reformers fled from the country: others remained to
abjure or die for their faith. A formulary was drawn up, to which
academicians were expected to subscribe, and this produced a great
excitement.
In 1545, proceedings were commenced against Felippo Valentino, a
young man of great promise, at Modena, suspected of heresy.
Hearing that an armed force was coming to apprehend him, he
escaped by night, leaving his books and papers behind, which, being
examined by the Inquisitors, brought many of his friends into
trouble. Next day, an edict was published, forbidding any to have
heretical or suspected books, or to dispute publicly or privately on
any point of religion, under the penalty, for the first offence, of a
hundred crowns of gold, or, if unable to pay that sum, of the
strappado. For the second offence, two thousand golden crowns, or
banishment. For the third, death.
Valentino and Castelvetro were cited to appear at Rome. The
popular feeling was so strong for them, that the Duke of Modena
was petitioned to intercede with the Pope, that the trial should be
suspended; which he declined. Valentino and Castelvetro, not
answering the citation, were excommunicated. The latter escaped to
Ferrara, thence to Geneva, and finally settled at Chiavenna. What
became of Valentino we are not told. He was gifted with an
extraordinary memory, and could correctly repeat a sermon or
lecture after hearing it once.
Another distinguished sufferer for the Truth was Olympia Morata,
who did not indeed seal her testimony with her blood, but who was
driven from home and country. Celio Curio had found refuge in her
father's house in Ferrara, about the time that Olympia went to reside
at the Ducal Palace, in order to inspire the little Princess Anne with
emulation in her classical studies. Here, her life was too gay and
worldly to be good for her.
"Had I remained longer at court," she afterwards wrote to Celio
Curio, "it would have been all over with me and my salvation. For
never, while I remained there, did I attain the knowledge of ought
high or heavenly, or read the Old or New Testament."
Yet she had two female friends of more than average merit—
Francesca Bucyronia and the Princess Lavinia della Rovere. Gifted
and pure-minded as they were, these interesting girls as yet only
cared for the things of this present life, and philosophy, falsely so
called.
Olympia was summoned from court by the mortal illness of her
beloved father; and, in the wholesome discipline of the sick-room,
received lessons of invaluable worth. He died, reposing on her
promise to supply a parent's place, as far as possible, to her little
brother and her three young sisters, and to minister with filial
devotion to her sickly mother.
It was a great charge, but she struggled bravely with her difficulties.
The great questions at issue between the Reformers and their foes
addressed themselves, also, to her attention, more forcibly than
heretofore; connected as they were with the fate of one in whom
her friend, the Princess Lavinia, took deep interest. A young man,
named Fannio, was consigned to the dungeons of Ferrara, for
adhering to the reformed opinions. To his wife and sister, who came
to see him in prison, he said, "Let it suffice you that, for your sake, I
once denied my Saviour! Had I then had the knowledge which, by
the grace of God, I have acquired since my fall, I would not have
yielded to your entreaties. Go home in peace!" Weeping, they went.
He lay two years in prison, "to the furtherance of the Gospel,"
inasmuch as "his bonds in Christ were manifest in all the palace."
Faithful friends resorted to him thither; among them were Lavinia
and Olympia. The peril of their visits perhaps added a little zest to
the impression of his teaching. In that gloomy cell, he and they and
a little handful of the faithful, prayed, and read the Scriptures, and
broke bread, and sang hymns, just as in the early times.
When it was found that many persons of rank, besides Lavinia, stole
to these meetings, while his fellow-prisoners were so wrought upon
by his heavenly-mindedness that they declared they had never
known what true liberty and happiness were till they found them in a
prison—Fannio was put into solitary confinement.
Though visitors were rigorously excluded, he reached them with his
letters; notwithstanding the repeated change of his gaolers. With
what intense interest must Lavinia and Olympia have pored over
these letters! In 1550, Fannio was brought to the stake, and, being
first strangled, was committed to the flames. He was the first of the
Reformers who laid down his life for his faith.
Olympia, meanwhile, bereft of court favour, led a troubled and
painful life. She wrote to Celio Curio—"After my father's death, I
remained alone; abandoned by those who ought to have supported
me. My sisters were involved in my misfortune, and only reaped
ingratitude for the devotion and services of years. How deeply I felt
it, you may readily conceive. Not one of those who had been our
friends in former times had now the courage to show the least
interest in us." She knew and he knew, indeed, that the Princess
Lavinia was a noteworthy exception.
This cheerless loneliness was broken by the constancy of a young
Bavarian student of medicine, named Grünthler, who had already
offered his hand to her and been refused. He now renewed his
addresses: his devotedness touched her heart, and she accepted
him. They were married very quietly in 1550. "Neither the
resentment of the Duke," she wrote to Curio, "nor all the miserable
circumstances which surrounded me, could induce him to abandon
his desire to make me his wife. So great and true a love has never
been surpassed."
Leaving her under the protection of Lavinia, Grünthler repaired to
Germany to find a home for her, where they might at least enjoy
freedom of conscience.
"Your departure," Olympia wrote to him, "was a great grief to me,
and your long absence is the greatest misfortune that could befall
me. I am always fancying you have had a fall, have broken your
limbs, or been frozen by the extreme cold. You know what the poet
says—
"Res est soliciti plena timoris amor."
"If you would alleviate this tormenting anxiety, let me know what
you are about; for my whole heart is yours, as you know full well."
Grünthler was so long finding what he wanted, that his good friend,
George Hermann, advised him to fetch his wife and live with him at
Augsberg, till something should turn up—which he did. Olympia's
grief was great at parting with her mother and sisters, whom she
had little hope of ever seeing again: her brother Emilio, eight years
of age, she took with her. Thus Italy lost one of its most
distinguished women.
Once settled in Germany, she was very happy. "We are still," she
wrote, "with our excellent friend, and I am delighted with my home
here. I pass my entire day in literary pursuits—me cum Musis
delecto—and have no cares to draw me away from them. I also
apply myself to the study of Holy Writ, which is so productive of
peace and contentment."
The occupation she chiefly found for her pen was translating the
Psalms of David into Greek verse. These her husband used to set to
music, and the singing of them formed the evening amusement of
their little circle.
After residing some months with George Hermann, they removed to
another friend, John Sinapi, a good physician who had married
Olympia's early companion, Francesca Bucyronia. At length they
obtained a humble home of their own at Schweinfurth on the Maine.
And here they dwelt usefully and happily till war and pestilence
raged around them. Schweinfurth was sacked: Olympia fled from it
barefoot, in worse plight than Giulia Gonzaga, for she had no horse
to carry her to the nearest refuge, ten miles off. "I might have been
taken," she said, "for the queen of the beggars."
At length they reached Erbach, where the good Countess received
her like a mother, and nursed her through her sickness. But Olympia
never recovered from the effects of that fearful flight; and an early
death crowned her beautiful and exemplary life.
The persecution which raged against the humbler confessors in
Ferrara, failed not to attack the Duchess herself, though the
daughter of a King of France. It was not till she had endured a short
imprisonment that she was intimidated into concealing her
convictions. On the death of the Duke, she returned to France,
where she made open profession of the reformed faith, and afforded
shelter to its confessors.
In the Venetian states, the persecution raged with great violence.
Francesco Spira, a lawyer of Padua, died in such agonies of mind at
having been induced, by the terrors of the Inquisition, to recant, that
Vergerio, the converted bishop of Capo d' Istria, who was present at
his death, was greatly affected by it. "To tell the truth," says he, "I
felt such a flame in my breast, that I could hardly help going to the
legate at Venice, and crying out, "Here I am! where are your prisons
and your fires?" Instead of this, he sought refuge among the
Grisons.
The way of putting the Venetian martyrs to death was not by fire but
by water. At dead of night, the prisoner was taken from his cell, and
put into a gondola, attended by a priest. He was rowed out to sea,
beyond "The two Castles," where another boat was waiting. A plank
was then laid across the two gondolas, upon which the prisoner,
heavily chained to a stone, was placed. On a given signal, the two
boats paddled different ways.
The first martyr who thus suffered was Giulio Giurlanda. When set
on the plank, he calmly bade the gondoliers farewell, and, calling on
the Lord, sank into the deep.
Antonio Bicetto, of Vicenza, followed his example, though urged to
recant by the most tempting bribes. Space would fail if I undertook
to recount all who in their turn were faithful unto death. Others
escaped; and there was not a city of note in Italy that did not swell
the list of fugitives. This shows how widely the reformed opinions
must have spread.
Nowhere was greater cruelty shown than to the Milanese. Galeazzo
Trezio, a man of noble birth, was sentenced to be burnt alive, which
he bore with the utmost fortitude. A young priest, after being half-
strangled, was literally roasted alive, and then thrown to the dogs.
At Naples, so great was the rigour of the Inquisition as seriously to
affect trade. Whole streets were deserted by their inhabitants.
Terrified by the severities exercised upon their brethren, a
considerable body of Neapolitans agreed to quit Italy together. But,
when they reached the Alps, and stopped to take a last view of their
beloved country, they burst into tears and resolved to return home.
They no sooner reached it than they were cast into prison.
But, of all the barbarities of which Rome was guilty at this time,
none were more horrible than those which were inflicted on the
Waldenses who had settled in Calabria. I have already related how
these peaceable people had founded a little colony, and, by their
exemplary lives, had won the good opinion of even the priests. They
now amounted to about four thousand persons, and they possessed
several towns in the neighbourhood of Coscenza, two of which were
Santo Xisto and La Guardia.
Cut off from all intercourse with their Waldensian brethren, these
colonists had habituated themselves to attend mass, without which
they found it difficult to maintain friendly relations with their
neighbours. Hearing of the spread of the reformed opinions in Italy,
similar to those for which their ancestors had bled, these Waldenses
became convinced they had sinned in conforming to Popish
observances, and they applied to their friends and ministers at
Pragela and Geneva, for teachers who should reform and restore
their discipline.
No sooner was this known at Rome, than two monks were sent to
reduce these Waldenses to obedience to the holy see. They began
very gently with the inhabitants of Santo Xisto, saying they had only
come to prevent them from lapsing into error; and they appointed a
time for the celebration of mass, which they enjoined every person
to attend.
Instead of this, the Waldenses, in a body, retreated into the woods,
only leaving behind them a few old people and children. The monks,
concealing their chagrin, repaired to La Guardia, and, having caused
the gates to be shut, assembled the inhabitants and told them their
brethren of Santo Xisto had renounced their errors, and they had
better follow their good example.
The poor simple people were talked over, and complied; but great
was their indignation when they found the deceit that had been
practised on them. They were eager immediately to join their
brethren in the woods, but were dissuaded by their feudal lord.
Meanwhile, the monks directed two companies of foot-soldiers to
beat the woods, and hunt down the fugitives in them like wild
beasts, which they did, with cries of "Ammazzi! ammazzi!" "Slay
them! slay them!"
Some of the Waldenses, securing themselves among the rocks,
demanded a parley with the captain of their assailants. They pleaded
for their wives and children, said they were willing peaceably to
leave the country, and implored him to withdraw his men. Instead of
this, the captain commanded an instant attack, most of the parleyers
were cut down, and the rest took to flight. San Xisto was given up to
fire and sword; and the fugitives still lurking in the woods, either
were put to death or perished with hunger.
The people of La Guardia were then given up to the tender mercies
of the Inquisition. My pen refuses to copy the account of the horrible
cruelties to which they were subjected. Sixty women were tortured,
most of whom died in prison, in consequence of their wounds
remaining undressed. Yet this was nothing to what afterwards
ensued. One of the Catholic historians says, "Some had their throats
cut, others were sawn asunder, others thrown from a high cliff: all
were cruelly, but deservedly put to death. It was strange to hear of
their obstinacy; for while the father saw his son put to death, and
the son his father, they not only exhibited no symptoms of grief, but
said joyfully that they should be angels of God! So much had the
devil, to whom they had given themselves up as prey, deceived
them!" [16]
[16] Tommaso Costa.

Martyrs of whom the world was not worthy! It is less sad, after all,
to read of the martyrdoms of Carnesecchi, and Di Monti, and
Paleario, and many others, than to find heresies and schisms
creeping into the little flock itself, and drawing many of them away
from the purity of that faith for which others died.
Unitarianism was the canker that ate into the bud of the Italian
Reformation. The opinions of Servetus and Socinus, and various
modifications of them, insinuated themselves into the minds of the
hapless exiles, who were scattered as sheep having no shepherd.
Camillo Renato was one of the leading schismatics; and though he
did not avow his own disbelief in the Trinity, his followers made no
scruple of doing so. Many were tossed in a wild sea of doubt; others
were swayed to and fro by every wind of doctrine; but we must not
forget that a great many were consistent and faithful to the end of
their course. Even Ochino's orthodoxy was suspected; though Calvin
saw no reason to doubt it. There was a cloud, however, over his
latter days.
Pius the Fourth was of a mild disposition, but he was not powerful
enough to overrule the inquisitors. A house beyond the Tiber was
appropriated to them, to which cells were added for criminals, or
those who were accounted such. This was called "the Lutheran
prison," and it was said to be built on the site of the ancient Circus
of Nero, in which so many Christians were delivered to the wild
beasts.
The persecution raged with redoubled fury under Pius the Fifth:
especially at Bologna, where "persons of all ranks were
indiscriminately subjected to the same imprisonment, tortures, and
death. In Rome, some were every day burnt, hanged, or beheaded;
all the prisons were filled, and they were obliged to seek new ones."
Think of the constancy of these confessors! Rome had no need to go
to Japan for martyrs. If she should hereafter have a Protestant
martyrology, many of her own sons and daughters may be enrolled
in it. "We know not what becomes of people here," wrote Muretus to
De Thou; "I am terrified every morning when I rise, lest I should be
told that such and such a one is no more: and if it should be so, we
should not dare to say a word."
And thus the Italian Reformation was crushed out! But its motto is
"Resurgam!"

II.
"The 'Alfabeto Christiano' is a book unknown even to bibliographers
for the last three centuries. It had its origin in an actual conversation
between Juan de Valdés, twin brother to the Latin secretary of the
Emperor Charles the Fifth, and Giulia Gonzaga, Duchess of Trajetto
and Countess of Fondi, at Naples, about the close of 1535, or the
beginning of the following year. At her request it was immediately
afterwards written down by him in Spanish, to promote her
instruction and refresh her memory. It now essentially conveys to us
the spirit and substance of the conversation in the precise form and
manner in which it took place between them."—Introduction by
Benjamin B. Wiffen, Esq., to his translation of the "Alfabeto
Christiano."
"It was printed at a time when for a few years the press of Venice
was comparatively free; and when, taking advantage of this liberty,
then existing nowhere else in Italy, it multiplied the tracts of the
Reformation by thousands. When the friends of Valdés were
afterwards persecuted at Naples, and his name condemned by the
authority of Rome, implicating by connection with him, one of the
most distinguished members of the noble family of the Gonzagas,—
all parties, friends equally with opponents, would of course be
concerned to observe silence on the subject; while all the friends of
the family would be urged alike by religious sentiment and by family
considerations to destroy silently and irrecoverably every copy of a
book that appeared to cast, by its association with her name, the
shadow of its principles upon those who were allied to her."—Ibid.
The passage describing the manner in which a stray copy fell into his
hands, and the circumstances under which he perused it, is one of
the pleasantest in Mr. Wiffen's Introduction. McCrie quotes a passage
from Fontaine, who tells us that "on taking down an old house at
Urbino, in 1728, the workmen disinterred a copy of Bruccioli's
'Paraphrase of St. Paul's Epistles,' with some books of Ochino,
Valdés, and others of the same kind, which had remained in
concealment for more than a century and a half."

III.
"Carnesecchi was secretary to Clement the Seventh, and afterwards
prothonotary to the Apostolic See. One of his preferments was an
abbey at Naples.... After the death of Clement, he retired from the
Roman court to Naples, where he became intimate with Juan de
Valdés. He was in that city in December, 1540, when Valdés died;
and if he did not himself receive his last confession, which is very
probable, he at least knew what it was, for his commendation of it
formed part of the accusation against him on his trial in 1567, before
the Inquisition at Rome; and after the death of Valdés he succeeded
to the confidence of Giulia Gonzaga. This correspondence brought
her also under the suspicion of the Inquisition on two occasions;
once in 1545, and again, a short time before her death, in 1566."—
Wiffen's Introd., &c.

IV.
"Few were the years of the life of Valdés after the conversation of
the 'Alfabeto Christiano,' yet during four, or at the most, five of
them, he presented to Giulia his translation from the Greek of the
Gospel according to Matthew, of the Psalms translated from the
Hebrew, of the Epistle to the Romans, from the Greek, with a
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like