Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Network Science with Python and NetworkX Quick Start Guide
Network Science with Python and NetworkX Quick Start Guide

Network Science with Python and NetworkX Quick Start Guide: Explore and visualize network data effectively

eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Network Science with Python and NetworkX Quick Start Guide

Working with Networks in NetworkX

The basic features of NetworkX are contained in several Python classes that represent different types of networks. In particular, this chapter discusses Graph, DiGraph, MultiGraph, and MultiDiGraph. These classes can be used to represent, analyze, and visualize most networks. In this chapter, you will learn to use these classes to work with real-world network data in NetworkX. The code examples in this and future chapters will assume that you have already imported the networkx package.

In this chapter, we will cover the following topics:

  • The Graph class: Understand the properties of undirected networks and how they are represented using the NetworkX Graph class.
  • Attributes: How to associate data with nodes and edges.
  • Edge weights: Learn how to quantify connection strength, and annotate edges with that information.
  • The DiGraph class: Understand...

The Graph class – undirected networks

In NetworkX, the Graph class is used to represent undirected networks and analyze their structure. The previous chapter showed how to create a network from scratch by adding nodes and edges. This section will instead use one of the ready-made networks available in NetworkX: Zachary's karate club (Zachary, 1977).

This network represents the friendships (edges) between members (nodes) of a karate club studied between 1970 and 1972. This particular karate club has long been of interest to sociologists and network scientists, because it eventually split into two different clubs after a disagreement between the instructor and the club president (this might explain why there aren't any famous studies of conflict resolution clubs). In the original study, Zachary used the network structure to predict which members would join which...

Adding attributes to nodes and edges

In the last chapter, I said that networks were entirely defined by the number of nodes and which nodes were connected. I lied. Kind of. Now that we're all a little older and wiser than we were in Chapter 1, What is a Network?, I can tell you the whole truth: sometimes, network nodes and edges are annotated with additional information. In the Graph class, each node and edge can have a set of attributes to store this additional information. Attributes can simply be a convenient place to store information related to the nodes and edges, or they can be used by visualizations and network algorithms.

The Graph class allows you to add any number of attributes to a node. For a G, network, each node's attributes are stored in the dict at G.nodes[v], where v is the node's ID. In the karate club example, the club members eventually split...

Adding edge weights

So far, all of the edges in this chapter have been unweighted, but the Graph class also supports weighted edges. Edge weights are handy when connections can have different strengths and when there is a way to quantify the strength of a connection; for example, how often two friends talk to each other, the volume of fluid a pipe can transport, or the number of direct flights between two cities.

The karate club network doesn't have any additional information about the strength of the edges, but there are relevant properties of those edges that can be calculated, such as the tie strength. Tie strength increases with the number of neighbors that two nodes have in common. It is motivated by the observation that closer friends tend to have more friends in common, and it can often reveal insight into the structure of a social network. The following code calculates...

The DiGraph class – when direction matters

So far, all of the edges in this chapter have been undirected, with no difference between an edge from A to B, and an edge from B to A. But not all relationships in life are so symmetric. If an employee-boss relationship is described by an undirected edge, it suggests that the employee can fire the boss as easily as the other way around. While possibly good for workplace morale, such arrangements aren't the norm. NetworkX supports directed edges through the DiGraph (directed graph) class.

Many of the operations already described for the Graph class translate seamlessly to the DiGraph class. Iterating through nodes and edges, accessing attributes, and visualization are all exactly the same. But there are a few differences. This section will describe the most important of these differences.

This section will use another social...

MultiGraph and MultiDiGraph – parallel edges

Meanwhile, in 18th-century Königsberg, both Graph and DiGraph fall short. Several of the bridges of Königsberg (discussed in Chapter 1, What is a Network?) connected the same two landmasses. In order to represent the bridges as a network, the nodes representing the land masses need to have multiple parallel edges, but the Graph class only allows one edge between a pair of nodes. For situations like this, NetworkX provides the MultiGraph and MultiDiGraph classes. For many applications, parallel edges can be combined into a single weighted edge, but when they can't, these classes can be used.

These MultiGraph and MultiDigraph classes work very much like Graph and DiGraph, but allow parallel edges. Any number of edges can be added between the same two endpoints. The following example reconstructs the Königsberg...

Summary

All networks are composed of nodes and edges, but different systems require nodes and edges with different attributes. This chapter introduced the Graph class for undirected networks, and the DiGraph class for directed networks, as well as the MultiGraph and MultiDiGraph classes. In addition, this chapter demonstrated how to attach data to nodes and edges using attributes. Now you know how to access the basic properties of a network in NetworkX using these classes, but where do those networks come from? The next chapter describes various techniques for creating networks from data.

References

The following is a list of resources that you can consider to get further knowledge:

  • Zachary, W. W. (1977). An information flow model for conflict and fission in small groups. Journal of anthropological research, 33(4).
  • Knecht, A. B. (2008). Friendship selection and friends’ influence (Doctoral dissertation). Utrecht University.
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand the terminology and basic concepts of network science
  • Leverage the power of Python and NetworkX to represent data as a network
  • Apply common techniques for working with network data of varying sizes

Description

NetworkX is a leading free and open source package used for network science with the Python programming language. NetworkX can track properties of individuals and relationships, find communities, analyze resilience, detect key network locations, and perform a wide range of important tasks. With the recent release of version 2, NetworkX has been updated to be more powerful and easy to use. If you’re a data scientist, engineer, or computational social scientist, this book will guide you in using the Python programming language to gain insights into real-world networks. Starting with the fundamentals, you’ll be introduced to the core concepts of network science, along with examples that use real-world data and Python code. This book will introduce you to theoretical concepts such as scale-free and small-world networks, centrality measures, and agent-based modeling. You’ll also be able to look for scale-free networks in real data and visualize a network using circular, directed, and shell layouts. By the end of this book, you’ll be able to choose appropriate network representations, use NetworkX to build and characterize networks, and uncover insights while working with real-world systems.

Who is this book for?

If you are a programmer or data scientist who wants to manipulate and analyze network data in Python, this book is perfect for you. Although prior knowledge of network science is not necessary, some Python programming experience will help you understand the concepts covered in the book easily.

What you will learn

  • Use Python and NetworkX to analyze the properties of individuals and relationships
  • Encode data in network nodes and edges using NetworkX
  • Manipulate, store, and summarize data in network nodes and edges
  • Visualize a network using circular, directed and shell layouts
  • Find out how simulating behavior on networks can give insights into real-world problems
  • Understand the ongoing impact of network science on society, and its ethical considerations

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 26, 2019
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781789950410
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 26, 2019
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781789950410
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 104.97
Python Machine Learning Cookbook
$38.99
Python Data Mining Quick Start Guide
$32.99
Network Science with Python and NetworkX Quick Start Guide
$32.99
Total $ 104.97 Stars icon
Banner background image

Table of Contents

13 Chapters
What is a Network? Chevron down icon Chevron up icon
Working with Networks in NetworkX Chevron down icon Chevron up icon
From Data to Networks Chevron down icon Chevron up icon
Affiliation Networks Chevron down icon Chevron up icon
The Small Scale - Nodes and Centrality Chevron down icon Chevron up icon
The Big Picture - Describing Networks Chevron down icon Chevron up icon
In-Between - Communities Chevron down icon Chevron up icon
Social Networks and Going Viral Chevron down icon Chevron up icon
Simulation and Analysis Chevron down icon Chevron up icon
Networks in Space and Time Chevron down icon Chevron up icon
Visualization Chevron down icon Chevron up icon
Conclusion Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Black May 09, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excelente book for beginners.The codes are really helpful
Amazon Verified review Amazon
David E. Battey Oct 01, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book does an excellent job of going from only a basic understanding of Python to all important aspects of NetworkX that are necessary for exploring and visualizing networks. There are excellent (and often humorous) examples, which were easy to run and understand. I used Jupyter Notebook, as recommended in the preface.I used this book for a Hackathon at work, and was able to quickly load up a data set that my team produces, which has different types of relationships between nodes, into a MultiDigraph. By adapting some of the examples in the book, I was able to create some pretty complex visualizations with very little effort.
Amazon Verified review Amazon
ajitB Mar 03, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
...makes this book the best book on use of NetworkX algo for understanding a wide variety of networks... social ones, economic ones, electrical ones ....and how to use many different metrics (e.g. Centrality) to understand what function these networks perform
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.