Table Of ContentEarly Praise for Complex Network Analysis in Python
This book is an excellent read for anyone who wants to learn the fundamentals
of complex network analysis with a focus on application. The case studies cover
a variety of topics and help readers link concepts to applications, providing readers
with a clear, well-structured, hands-on experience that deepens their understand-
ing of the concepts without requiring Python programming experience.
➤ Kate Li, PhD
Associate Professor, Sawyer Business School, Suffolk University
As a social scientist interested in network analysis but having limited knowledge
of Python, I found the book very useful. The author explains technical problems
in a way that is easy to understand for non–computer scientists. It is a great in-
troduction for those interested in network analysis seeking to apply the method
in their research.
➤ Weiqi Zhang
Associate Professor of Government, Suffolk University
Complex Network Analysis in Python is a thorough introduction to the tools and
techniques needed for complex network analysis. Real-world case studies
demonstrate how one can easily use powerful Python packages to analyze large
networks and derive meaningful analytic insights.
➤ Mike Lin
Senior Software Engineer, Fugue, Inc.
Having a deep understanding of complex network analysis is hard; however, this
book will help you learn the basics to start mastering the skills you need to analyze
complex networks, not only at a conceptual level, but also at a practical level, by
putting the theory into action using the Python programming language.
➤ Jose Arturo Mora
Head of Information Technology and Innovation, BNN Mexico
Complex networks have diverse applications in various fields, including health
care, social networks, and machine learning. I found this book to be an excellent
and comprehensive resource guide for researchers, students, and professionals
interested in applying complex networks.
➤ Rajesh Kumar Pandey
Graduate Student, IIT Hyderabad
Complex Network Analysis in Python
Recognize → Construct → Visualize → Analyze → Interpret
Dmitry Zinoviev
The Pragmatic Bookshelf
Raleigh, North Carolina
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic books, screencasts, and audio books can help you and your team create
better software and have more fun. Visit us at https://pragprog.com.
The team that produced this book includes:
Publisher: Andy Hunt
VP of Operations: Janet Furlow
Managing Editor: Brian MacDonald
Supervising Editor: Jacquelyn Carter
Development Editor: Adaobi Obi Tulton
Copy Editor: Nicole Abramowitz
Indexing: Potomac Indexing, LLC
Layout: Gilson Graphics
For sales, volume licensing, and support, please contact support@pragprog.com.
For international rights, please contact rights@pragprog.com.
Copyright © 2018 The Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise,
without the prior consent of the publisher.
Printed in the United States of America.
ISBN-13: 978-1-68050-269-5
Encoded using the finest acid-free high-entropy binary digits.
Book version: P1.0—January 2018
To my beautiful and most intelligent wife,
Anna, and to our children: graceful ballerina,
Eugenia, and romantic gamer, Roman.
Contents
Acknowledgments . . . . . . . . . . . xi
Preface . . . . . . . . . . . . . . xiii
1. The Art of Seeing Networks . . . . . . . . . 1
Know Thy Networks 2
Enter Complex Network Analysis 5
Draw Your First Network with Paper and Pencil 6
Part I — Elementary Networks and Tools
2. Surveying the Tools of the Craft . . . . . . . . 11
Do Not Weave Your Own Networks 11
Glance at iGraph 12
Appreciate the Power of graph-tool 13
Accept NetworkX 15
Keep in Mind NetworKit 15
Compare the Toolkits 16
3. Introducing NetworkX . . . . . . . . . . 17
Construct a Simple Network with NetworkX 17
Add Attributes 23
Visualize a Network with Matplotlib 25
Share and Preserve Networks 29
4. Introducing Gephi . . . . . . . . . . . 31
Worth 1,000 Words 31
Import and Modify a Simple Network with Gephi 32
Explore the Network 34
Sketch the Network 36
Contents • viii
Prepare a Presentation-Quality Image 38
Combine Gephi and NetworkX 40
5. Case Study: Constructing a Network of Wikipedia Pages . . 41
Get the Data, Build the Network 42
Eliminate Duplicates 45
Truncate the Network 46
Explore the Network 47
Part II — Networks Based on Explicit Relationships
6. Understanding Social Networks . . . . . . . . 53
Understand Egocentric and Sociocentric Networks 53
Recognize Communication Networks 61
Appreciate Synthetic Networks 63
Distinguish Strong and Weak Ties 66
7. Mastering Advanced Network Construction . . . . . 69
Create Networks from Adjacency and Incidence Matrices 69
Work with Edge Lists and Node Dictionaries 76
Generate Synthetic Networks 78
Slice Weighted Networks 79
8. Measuring Networks . . . . . . . . . . . 83
Start with Global Measures 83
Explore Neighborhoods 84
Think in Terms of Paths 88
Choose the Right Centralities 92
Estimate Network Uniformity Through Assortativity 97
9. Case Study: Panama Papers . . . . . . . . 101
Create a Network of Entities and Officers 101
Draw the Network 104
Analyze the Network 105
Build a “Panama” Network with Pandas 108
Part III — Networks Based on Co-Occurrences
10. Constructing Semantic and Product Networks . . . . 115
Semantic Networks 116
Product Networks 120