🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Data Analytics Notes
Topic #88

Graph Analytics & Network Data

By the end of this lesson, you will be able to model relationships as graphs and calculate basic network metrics like degree centrality using Python.

What it is

Graph analytics focuses on analyzing entities (nodes) and their relationships (edges). Unlike tabular data where rows are independent, graph data emphasizes connectivity. The mental model shifts from "what is this record?" to "who is connected to whom?". Key terms include Nodes (vertices/entities), Edges (links/relationships), Degree (number of connections a node has), and Centrality (measures of importance within the network).

Why it matters

  • Fraud Detection: Identifying suspicious clusters of accounts sharing devices or addresses.
  • Social Network Analysis: Finding influencers or communities within user interaction data.
  • Recommendation Engines: Suggesting products based on what similar users bought (collaborative filtering).
  • Supply Chain Optimization: Mapping dependencies between suppliers to identify single points of failure.

Syntax or steps

The standard library for this in Python is networkx. The workflow involves: 1. Creating an empty graph object. 2. Adding nodes and edges from your data source. 3. Applying algorithms to compute metrics. 4. Visualizing or exporting results.

Example

import networkx as nx

# 1. Create a directed graph
G = nx.DiGraph()

# 2. Add edges representing transactions (User A sent money to User B)
edges = [
    ("Alice", "Bob"),
    ("Bob", "Charlie"),
    ("Alice", "Charlie"),
    ("David", "Alice")
]
G.add_edges_from(edges)

# 3. Calculate Degree Centrality (normalized by number of nodes - 1)
centrality = nx.degree_centrality(G)

# 4. Print results sorted by importance
for node, score in sorted(centrality.items(), key=lambda x: x[1], reverse=True):
    print(f"{node}: {score:.2f}")
Explanation: - nx.DiGraph() creates a directed graph, essential if relationship direction matters (e.g., who initiated contact). - add_edges_from() efficiently loads multiple connections at once. - degree_centrality() computes how many connections each node has relative to the maximum possible. In this example, Alice has high centrality because she connects to Bob, Charlie, and receives from David.

Common mistakes

  • Ignoring Directionality: Using an undirected graph (nx.Graph) when the relationship is asymmetric (e.g., "follows" vs. "is friends with"). This inflates connection counts incorrectly.
  • Overlooking Isolated Nodes: Nodes with no edges may skew average metrics if not handled explicitly during analysis.
  • Assuming Small World Properties: Not all networks are small-world; applying shortest-path algorithms without checking connectivity can yield infinite distances or errors.
  • Memory Mismanagement: Loading massive edge lists into memory without chunking or using sparse representations can crash applications.

When to use it

Compare graph analytics with traditional relational SQL queries.
FeatureGraph AnalyticsRelational SQL
Best ForDeep traversal (friends of friends)Aggregations & simple joins
PerformanceFast for multi-hop queriesSlow for recursive joins
Data ModelFlexible schemaRigid table structure
Use graph analytics when the question involves paths, clusters, or influence propagation. Use SQL when the question involves counting, summing, or filtering specific attributes.

Practice

Guided Exercise: Modify the code above to find the shortest path from "David" to "Charlie". Use nx.shortest_path(G, source="David", target="Charlie"). Expected output: ['David', 'Alice', 'Charlie']. Challenge: Identify which node has the highest in-degree (most incoming edges) using G.in_degree(). Hint: Iterate through nodes and compare values.

Quick check

Question: If you want to find people who are two steps away from a specific user, which metric or algorithm is most relevant? Answer: You would use a breadth-first search (BFS) limited to depth 2, or calculate the adjacency matrix squared ($A^2$) to count paths of length 2.

Summary

Graph analytics transforms flat data into a web of relationships, revealing insights about connectivity and influence that tables cannot. By mastering tools like networkx, you can detect patterns such as fraud rings or community structures effectively.

Want to go beyond the notes?

Join CodingNow 2.0's Data Analytics course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Graph Analytics & Network Data – FAQs

Quick answers about learning Graph Analytics & Network Data in Data Analytics.

This free note from CodingNow 2.0 explains Graph Analytics & Network Data in Data Analytics — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Data Analytics topic on CodingNow 2.0, including Graph Analytics & Network Data, is 100% free with no signup required.
With focused practice, most students grasp Graph Analytics & Network Data in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now