tynbl.github.io

实战案例7:“权利的游戏”人物关系分析

1. 项目描述:

《权力的游戏》(英语:Game of Thrones)是一部中世纪史诗奇幻题材的美国电视连续剧。该剧以美国作家乔治·R·R·马丁的奇幻文学《冰与火之歌》系列作为基础改编创作,由大卫·贝尼奥夫和D·B·魏斯(D. B. Weiss)编剧执笔,再由HBO有线电视联播网推出,该剧剧名取自于小说《冰与火之歌》的第一部。

剧中虚构出的中世纪大陆和九大家族的争权夺利,非常有看点,剧情的发展也让人无法预料,了解众多的人物和复杂的关系对于了解剧情很有帮助,本项目通过社交网络分析了这块奇幻大陆和九大家族。

2. 数据集描述:

3. 项目任务:

4. 项目实现:

# 引入必要的包
import os
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

%matplotlib notebook
# 解决matplotlib显示中文问题
# 仅适用于Windows
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题

# MacOS请参考 http://wenda.chinahadoop.cn/question/5304 修改字体配置

4.1 数据查看

# 指定数据集路径
dataset_path = '../data'

# 加载数据
book1_df = pd.read_csv(os.path.join(dataset_path, 'asoiaf-book1-edges.csv'))
book2_df = pd.read_csv(os.path.join(dataset_path, 'asoiaf-book2-edges.csv'))
book3_df = pd.read_csv(os.path.join(dataset_path, 'asoiaf-book3-edges.csv'))
book4_df = pd.read_csv(os.path.join(dataset_path, 'asoiaf-book4-edges.csv'))
book5_df = pd.read_csv(os.path.join(dataset_path, 'asoiaf-book5-edges.csv'))

book1_df.head()
Source Target Type weight book
0 Addam-Marbrand Jaime-Lannister Undirected 3 1
1 Addam-Marbrand Tywin-Lannister Undirected 6 1
2 Aegon-I-Targaryen Daenerys-Targaryen Undirected 5 1
3 Aegon-I-Targaryen Eddard-Stark Undirected 4 1
4 Aemon-Targaryen-(Maester-Aemon) Alliser-Thorne Undirected 4 1

4.2 构建网络

# 从dataframe构建网络
G_book1 = nx.from_pandas_dataframe(book1_df, 'Source', 'Target', edge_attr=['weight', 'book'])
G_book2 = nx.from_pandas_dataframe(book2_df, 'Source', 'Target', edge_attr=['weight', 'book'])
G_book3 = nx.from_pandas_dataframe(book3_df, 'Source', 'Target', edge_attr=['weight', 'book'])
G_book4 = nx.from_pandas_dataframe(book4_df, 'Source', 'Target', edge_attr=['weight', 'book'])
G_book5 = nx.from_pandas_dataframe(book5_df, 'Source', 'Target', edge_attr=['weight', 'book'])

G_books = [G_book1, G_book2, G_book3, G_book4, G_book5]
# 查看网络的边
G_book1.edges(data=True)
[('Addam-Marbrand', 'Jaime-Lannister', {'book': 1, 'weight': 3}),
 ('Addam-Marbrand', 'Tywin-Lannister', {'book': 1, 'weight': 6}),
 ('Jaime-Lannister', 'Aerys-II-Targaryen', {'book': 1, 'weight': 5}),
 ('Jaime-Lannister', 'Barristan-Selmy', {'book': 1, 'weight': 4}),
 ('Jaime-Lannister', 'Brynden-Tully', {'book': 1, 'weight': 7}),
 ('Jaime-Lannister', 'Catelyn-Stark', {'book': 1, 'weight': 9}),
 ('Jaime-Lannister', 'Cersei-Lannister', {'book': 1, 'weight': 16}),
 ('Jaime-Lannister', 'Eddard-Stark', {'book': 1, 'weight': 27}),
 ('Jaime-Lannister', 'Edmure-Tully', {'book': 1, 'weight': 4}),
 ('Jaime-Lannister', 'Galbart-Glover', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Gregor-Clegane', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Harys-Swyft', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Joffrey-Baratheon', {'book': 1, 'weight': 12}),
 ('Jaime-Lannister', 'Jon-Arryn', {'book': 1, 'weight': 5}),
 ('Jaime-Lannister', 'Jory-Cassel', {'book': 1, 'weight': 4}),
 ('Jaime-Lannister', 'Kevan-Lannister', {'book': 1, 'weight': 4}),
 ('Jaime-Lannister', 'Loras-Tyrell', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Lysa-Arryn', {'book': 1, 'weight': 6}),
 ('Jaime-Lannister', 'Petyr-Baelish', {'book': 1, 'weight': 7}),
 ('Jaime-Lannister', 'Renly-Baratheon', {'book': 1, 'weight': 4}),
 ('Jaime-Lannister', 'Rickard-Karstark', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Robb-Stark', {'book': 1, 'weight': 9}),
 ('Jaime-Lannister', 'Robert-Baratheon', {'book': 1, 'weight': 24}),
 ('Jaime-Lannister', 'Rodrik-Cassel', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Sandor-Clegane', {'book': 1, 'weight': 12}),
 ('Jaime-Lannister', 'Sansa-Stark', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Tyrion-Lannister', {'book': 1, 'weight': 36}),
 ('Jaime-Lannister', 'Tywin-Lannister', {'book': 1, 'weight': 16}),
 ('Jaime-Lannister', 'Varys', {'book': 1, 'weight': 3}),
 ('Jaime-Lannister', 'Wyl-(guard)', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Bronn', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Brynden-Tully', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Catelyn-Stark', {'book': 1, 'weight': 7}),
 ('Tywin-Lannister', 'Cersei-Lannister', {'book': 1, 'weight': 10}),
 ('Tywin-Lannister', 'Eddard-Stark', {'book': 1, 'weight': 18}),
 ('Tywin-Lannister', 'Gregor-Clegane', {'book': 1, 'weight': 6}),
 ('Tywin-Lannister', 'Joffrey-Baratheon', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Jon-Umber-(Greatjon)', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Kevan-Lannister', {'book': 1, 'weight': 9}),
 ('Tywin-Lannister', 'Marq-Piper', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Pycelle', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Rhaegar-Targaryen', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Robb-Stark', {'book': 1, 'weight': 9}),
 ('Tywin-Lannister', 'Robert-Baratheon', {'book': 1, 'weight': 13}),
 ('Tywin-Lannister', 'Roose-Bolton', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Stannis-Baratheon', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Theon-Greyjoy', {'book': 1, 'weight': 3}),
 ('Tywin-Lannister', 'Tyrion-Lannister', {'book': 1, 'weight': 40}),
 ('Tywin-Lannister', 'Varys', {'book': 1, 'weight': 4}),
 ('Tywin-Lannister', 'Walder-Frey', {'book': 1, 'weight': 8}),
 ('Aegon-I-Targaryen', 'Daenerys-Targaryen', {'book': 1, 'weight': 5}),
 ('Aegon-I-Targaryen', 'Eddard-Stark', {'book': 1, 'weight': 4}),
 ('Daenerys-Targaryen', 'Aggo', {'book': 1, 'weight': 11}),
 ('Daenerys-Targaryen', 'Cohollo', {'book': 1, 'weight': 7}),
 ('Daenerys-Targaryen', 'Doreah', {'book': 1, 'weight': 15}),
 ('Daenerys-Targaryen', 'Drogo', {'book': 1, 'weight': 101}),
 ('Daenerys-Targaryen', 'Eddard-Stark', {'book': 1, 'weight': 5}),
 ('Daenerys-Targaryen', 'Eroeh', {'book': 1, 'weight': 5}),
 ('Daenerys-Targaryen', 'Haggo', {'book': 1, 'weight': 12}),
 ('Daenerys-Targaryen', 'Illyrio-Mopatis', {'book': 1, 'weight': 24}),
 ('Daenerys-Targaryen', 'Irri', {'book': 1, 'weight': 25}),
 ('Daenerys-Targaryen', 'Jhiqui', {'book': 1, 'weight': 26}),
 ('Daenerys-Targaryen', 'Jhogo', {'book': 1, 'weight': 17}),
 ('Daenerys-Targaryen', 'Jorah-Mormont', {'book': 1, 'weight': 75}),
 ('Daenerys-Targaryen', 'Mirri-Maz-Duur', {'book': 1, 'weight': 31}),
 ('Daenerys-Targaryen', 'Qotho', {'book': 1, 'weight': 18}),
 ('Daenerys-Targaryen', 'Quaro', {'book': 1, 'weight': 5}),
 ('Daenerys-Targaryen', 'Rakharo', {'book': 1, 'weight': 4}),
 ('Daenerys-Targaryen', 'Rhaegar-Targaryen', {'book': 1, 'weight': 4}),
 ('Daenerys-Targaryen', 'Robert-Baratheon', {'book': 1, 'weight': 11}),
 ('Daenerys-Targaryen', 'Varys', {'book': 1, 'weight': 5}),
 ('Daenerys-Targaryen', 'Viserys-Targaryen', {'book': 1, 'weight': 37}),
 ('Eddard-Stark', 'Aerys-II-Targaryen', {'book': 1, 'weight': 10}),
 ('Eddard-Stark', 'Alyn', {'book': 1, 'weight': 11}),
 ('Eddard-Stark', 'Arya-Stark', {'book': 1, 'weight': 30}),
 ('Eddard-Stark', 'Balon-Greyjoy', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Barristan-Selmy', {'book': 1, 'weight': 28}),
 ('Eddard-Stark', 'Beric-Dondarrion', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Bran-Stark', {'book': 1, 'weight': 19}),
 ('Eddard-Stark', 'Brandon-Stark', {'book': 1, 'weight': 11}),
 ('Eddard-Stark', 'Catelyn-Stark', {'book': 1, 'weight': 64}),
 ('Eddard-Stark', 'Cayn', {'book': 1, 'weight': 7}),
 ('Eddard-Stark', 'Cersei-Lannister', {'book': 1, 'weight': 69}),
 ('Eddard-Stark', 'Daryn-Hornwood', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Desmond', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Edmure-Tully', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Galbart-Glover', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Gendry', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Gerold-Hightower', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Gregor-Clegane', {'book': 1, 'weight': 10}),
 ('Eddard-Stark', 'Harwin', {'book': 1, 'weight': 5}),
 ('Eddard-Stark', 'High-Septon-(fat_one)', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Howland-Reed', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Ilyn-Payne', {'book': 1, 'weight': 6}),
 ('Eddard-Stark', 'Jacks', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Janos-Slynt', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Joffrey-Baratheon', {'book': 1, 'weight': 26}),
 ('Eddard-Stark', 'Jon-Arryn', {'book': 1, 'weight': 47}),
 ('Eddard-Stark', 'Jon-Snow', {'book': 1, 'weight': 38}),
 ('Eddard-Stark', 'Jory-Cassel', {'book': 1, 'weight': 32}),
 ('Eddard-Stark', 'Joss', {'book': 1, 'weight': 5}),
 ('Eddard-Stark', 'Loras-Tyrell', {'book': 1, 'weight': 12}),
 ('Eddard-Stark', 'Luwin', {'book': 1, 'weight': 16}),
 ('Eddard-Stark', 'Lyanna-Stark', {'book': 1, 'weight': 19}),
 ('Eddard-Stark', 'Lysa-Arryn', {'book': 1, 'weight': 12}),
 ('Eddard-Stark', 'Marq-Piper', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Mordane', {'book': 1, 'weight': 11}),
 ('Eddard-Stark', 'Mycah', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Petyr-Baelish', {'book': 1, 'weight': 81}),
 ('Eddard-Stark', 'Porther', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Pycelle', {'book': 1, 'weight': 33}),
 ('Eddard-Stark', 'Raymun-Darry', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Renly-Baratheon', {'book': 1, 'weight': 33}),
 ('Eddard-Stark', 'Rhaegar-Targaryen', {'book': 1, 'weight': 10}),
 ('Eddard-Stark', 'Rickard-Karstark', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Rickon-Stark', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Robb-Stark', {'book': 1, 'weight': 16}),
 ('Eddard-Stark', 'Robert-Baratheon', {'book': 1, 'weight': 291}),
 ('Eddard-Stark', 'Rodrik-Cassel', {'book': 1, 'weight': 7}),
 ('Eddard-Stark', 'Sandor-Clegane', {'book': 1, 'weight': 10}),
 ('Eddard-Stark', 'Sansa-Stark', {'book': 1, 'weight': 34}),
 ('Eddard-Stark', 'Stannis-Baratheon', {'book': 1, 'weight': 18}),
 ('Eddard-Stark', 'Syrio-Forel', {'book': 1, 'weight': 6}),
 ('Eddard-Stark', 'Theon-Greyjoy', {'book': 1, 'weight': 5}),
 ('Eddard-Stark', 'Tobho-Mott', {'book': 1, 'weight': 7}),
 ('Eddard-Stark', 'Tomard', {'book': 1, 'weight': 15}),
 ('Eddard-Stark', 'Torrhen-Karstark', {'book': 1, 'weight': 5}),
 ('Eddard-Stark', 'Tregar', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Tyrion-Lannister', {'book': 1, 'weight': 21}),
 ('Eddard-Stark', 'Varly', {'book': 1, 'weight': 4}),
 ('Eddard-Stark', 'Varys', {'book': 1, 'weight': 61}),
 ('Eddard-Stark', 'Vayon-Poole', {'book': 1, 'weight': 12}),
 ('Eddard-Stark', 'Wyl-(guard)', {'book': 1, 'weight': 3}),
 ('Eddard-Stark', 'Wylla', {'book': 1, 'weight': 3}),
 ('Aemon-Targaryen-(Maester-Aemon)',
  'Alliser-Thorne',
  {'book': 1, 'weight': 4}),
 ('Aemon-Targaryen-(Maester-Aemon)', 'Bowen-Marsh', {'book': 1, 'weight': 4}),
 ('Aemon-Targaryen-(Maester-Aemon)', 'Chett', {'book': 1, 'weight': 9}),
 ('Aemon-Targaryen-(Maester-Aemon)', 'Clydas', {'book': 1, 'weight': 5}),
 ('Aemon-Targaryen-(Maester-Aemon)',
  'Jeor-Mormont',
  {'book': 1, 'weight': 13}),
 ('Aemon-Targaryen-(Maester-Aemon)', 'Jon-Snow', {'book': 1, 'weight': 34}),
 ('Aemon-Targaryen-(Maester-Aemon)',
  'Samwell-Tarly',
  {'book': 1, 'weight': 5}),
 ('Alliser-Thorne', 'Bowen-Marsh', {'book': 1, 'weight': 3}),
 ('Alliser-Thorne', 'Grenn', {'book': 1, 'weight': 3}),
 ('Alliser-Thorne', 'Halder', {'book': 1, 'weight': 4}),
 ('Alliser-Thorne', 'Jeor-Mormont', {'book': 1, 'weight': 10}),
 ('Alliser-Thorne', 'Jon-Snow', {'book': 1, 'weight': 32}),
 ('Alliser-Thorne', 'Pypar', {'book': 1, 'weight': 4}),
 ('Alliser-Thorne', 'Rast', {'book': 1, 'weight': 5}),
 ('Alliser-Thorne', 'Samwell-Tarly', {'book': 1, 'weight': 8}),
 ('Alliser-Thorne', 'Tyrion-Lannister', {'book': 1, 'weight': 7}),
 ('Bowen-Marsh', 'Jeor-Mormont', {'book': 1, 'weight': 8}),
 ('Bowen-Marsh', 'Jon-Snow', {'book': 1, 'weight': 10}),
 ('Bowen-Marsh', 'Samwell-Tarly', {'book': 1, 'weight': 3}),
 ('Chett', 'Jon-Snow', {'book': 1, 'weight': 4}),
 ('Chett', 'Samwell-Tarly', {'book': 1, 'weight': 6}),
 ('Jeor-Mormont', 'Benjen-Stark', {'book': 1, 'weight': 9}),
 ('Jeor-Mormont', 'Bran-Stark', {'book': 1, 'weight': 4}),
 ('Jeor-Mormont', 'Gared', {'book': 1, 'weight': 4}),
 ('Jeor-Mormont', 'Grenn', {'book': 1, 'weight': 3}),
 ('Jeor-Mormont', 'Jaremy-Rykker', {'book': 1, 'weight': 11}),
 ('Jeor-Mormont', 'Jon-Snow', {'book': 1, 'weight': 81}),
 ('Jeor-Mormont', 'Robert-Baratheon', {'book': 1, 'weight': 4}),
 ('Jeor-Mormont', 'Samwell-Tarly', {'book': 1, 'weight': 8}),
 ('Jeor-Mormont', 'Tyrion-Lannister', {'book': 1, 'weight': 23}),
 ('Jeor-Mormont', 'Yoren', {'book': 1, 'weight': 3}),
 ('Jon-Snow', 'Albett', {'book': 1, 'weight': 5}),
 ('Jon-Snow', 'Arya-Stark', {'book': 1, 'weight': 37}),
 ('Jon-Snow', 'Benjen-Stark', {'book': 1, 'weight': 41}),
 ('Jon-Snow', 'Bran-Stark', {'book': 1, 'weight': 56}),
 ('Jon-Snow', 'Catelyn-Stark', {'book': 1, 'weight': 14}),
 ('Jon-Snow', 'Cersei-Lannister', {'book': 1, 'weight': 4}),
 ('Jon-Snow', 'Dareon', {'book': 1, 'weight': 6}),
 ('Jon-Snow', 'Donal-Noye', {'book': 1, 'weight': 7}),
 ('Jon-Snow', 'Dywen', {'book': 1, 'weight': 4}),
 ('Jon-Snow', 'Grenn', {'book': 1, 'weight': 31}),
 ('Jon-Snow', 'Halder', {'book': 1, 'weight': 23}),
 ('Jon-Snow', 'Hobb', {'book': 1, 'weight': 5}),
 ('Jon-Snow', 'Jaremy-Rykker', {'book': 1, 'weight': 7}),
 ('Jon-Snow', 'Joffrey-Baratheon', {'book': 1, 'weight': 10}),
 ('Jon-Snow', 'Jory-Cassel', {'book': 1, 'weight': 3}),
 ('Jon-Snow', 'Luwin', {'book': 1, 'weight': 10}),
 ('Jon-Snow', 'Matthar', {'book': 1, 'weight': 3}),
 ('Jon-Snow', 'Mordane', {'book': 1, 'weight': 4}),
 ('Jon-Snow', 'Othor', {'book': 1, 'weight': 5}),
 ('Jon-Snow', 'Pypar', {'book': 1, 'weight': 45}),
 ('Jon-Snow', 'Rast', {'book': 1, 'weight': 8}),
 ('Jon-Snow', 'Rickon-Stark', {'book': 1, 'weight': 11}),
 ('Jon-Snow', 'Robb-Stark', {'book': 1, 'weight': 53}),
 ('Jon-Snow', 'Robert-Baratheon', {'book': 1, 'weight': 18}),
 ('Jon-Snow', 'Rodrik-Cassel', {'book': 1, 'weight': 3}),
 ('Jon-Snow', 'Samwell-Tarly', {'book': 1, 'weight': 81}),
 ('Jon-Snow', 'Sansa-Stark', {'book': 1, 'weight': 8}),
 ('Jon-Snow', 'Theon-Greyjoy', {'book': 1, 'weight': 8}),
 ('Jon-Snow', 'Todder', {'book': 1, 'weight': 13}),
 ('Jon-Snow', 'Tyrion-Lannister', {'book': 1, 'weight': 56}),
 ('Jon-Snow', 'Yoren', {'book': 1, 'weight': 6}),
 ('Samwell-Tarly', 'Grenn', {'book': 1, 'weight': 8}),
 ('Samwell-Tarly', 'Halder', {'book': 1, 'weight': 6}),
 ('Samwell-Tarly', 'Pypar', {'book': 1, 'weight': 11}),
 ('Samwell-Tarly', 'Randyll-Tarly', {'book': 1, 'weight': 5}),
 ('Samwell-Tarly', 'Rast', {'book': 1, 'weight': 3}),
 ('Samwell-Tarly', 'Robb-Stark', {'book': 1, 'weight': 4}),
 ('Aerys-II-Targaryen', 'Brandon-Stark', {'book': 1, 'weight': 4}),
 ('Aerys-II-Targaryen', 'Gerold-Hightower', {'book': 1, 'weight': 3}),
 ('Aerys-II-Targaryen', 'Jon-Arryn', {'book': 1, 'weight': 3}),
 ('Aerys-II-Targaryen', 'Robert-Baratheon', {'book': 1, 'weight': 12}),
 ('Brandon-Stark', 'Lyanna-Stark', {'book': 1, 'weight': 4}),
 ('Brandon-Stark', 'Petyr-Baelish', {'book': 1, 'weight': 14}),
 ('Brandon-Stark', 'Rickard-Stark', {'book': 1, 'weight': 3}),
 ('Brandon-Stark', 'Robert-Baratheon', {'book': 1, 'weight': 5}),
 ('Gerold-Hightower', 'Arthur-Dayne', {'book': 1, 'weight': 4}),
 ('Gerold-Hightower', 'Oswell-Whent', {'book': 1, 'weight': 3}),
 ('Gerold-Hightower', 'Robert-Baratheon', {'book': 1, 'weight': 4}),
 ('Jon-Arryn', 'Barristan-Selmy', {'book': 1, 'weight': 4}),
 ('Jon-Arryn', 'Bran-Stark', {'book': 1, 'weight': 7}),
 ('Jon-Arryn', 'Catelyn-Stark', {'book': 1, 'weight': 11}),
 ('Jon-Arryn', 'Cersei-Lannister', {'book': 1, 'weight': 7}),
 ('Jon-Arryn', 'Hugh', {'book': 1, 'weight': 3}),
 ('Jon-Arryn', 'Lysa-Arryn', {'book': 1, 'weight': 12}),
 ('Jon-Arryn', 'Petyr-Baelish', {'book': 1, 'weight': 4}),
 ('Jon-Arryn', 'Pycelle', {'book': 1, 'weight': 11}),
 ('Jon-Arryn', 'Robert-Baratheon', {'book': 1, 'weight': 32}),
 ('Jon-Arryn', 'Stannis-Baratheon', {'book': 1, 'weight': 13}),
 ('Jon-Arryn', 'Tyrion-Lannister', {'book': 1, 'weight': 5}),
 ('Jon-Arryn', 'Varys', {'book': 1, 'weight': 5}),
 ('Robert-Baratheon', 'Alyn', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Arya-Stark', {'book': 1, 'weight': 8}),
 ('Robert-Baratheon', 'Balon-Greyjoy', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Barristan-Selmy', {'book': 1, 'weight': 40}),
 ('Robert-Baratheon', 'Benjen-Stark', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Beric-Dondarrion', {'book': 1, 'weight': 5}),
 ('Robert-Baratheon', 'Bran-Stark', {'book': 1, 'weight': 11}),
 ('Robert-Baratheon', 'Catelyn-Stark', {'book': 1, 'weight': 22}),
 ('Robert-Baratheon', 'Cersei-Lannister', {'book': 1, 'weight': 72}),
 ('Robert-Baratheon', 'Drogo', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Gregor-Clegane', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Hoster-Tully', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Illyrio-Mopatis', {'book': 1, 'weight': 6}),
 ('Robert-Baratheon', 'Ilyn-Payne', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Janos-Slynt', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Jeyne-Poole', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Joffrey-Baratheon', {'book': 1, 'weight': 30}),
 ('Robert-Baratheon', 'Jorah-Mormont', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Jory-Cassel', {'book': 1, 'weight': 7}),
 ('Robert-Baratheon', 'Lancel-Lannister', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Loras-Tyrell', {'book': 1, 'weight': 4}),
 ('Robert-Baratheon', 'Lyanna-Stark', {'book': 1, 'weight': 9}),
 ('Robert-Baratheon', 'Lysa-Arryn', {'book': 1, 'weight': 5}),
 ('Robert-Baratheon', 'Meryn-Trant', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Mordane', {'book': 1, 'weight': 7}),
 ('Robert-Baratheon', 'Myrcella-Baratheon', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Petyr-Baelish', {'book': 1, 'weight': 30}),
 ('Robert-Baratheon', 'Pycelle', {'book': 1, 'weight': 26}),
 ('Robert-Baratheon', 'Raymun-Darry', {'book': 1, 'weight': 8}),
 ('Robert-Baratheon', 'Renly-Baratheon', {'book': 1, 'weight': 42}),
 ('Robert-Baratheon', 'Rhaegar-Targaryen', {'book': 1, 'weight': 22}),
 ('Robert-Baratheon', 'Robb-Stark', {'book': 1, 'weight': 6}),
 ('Robert-Baratheon', 'Sandor-Clegane', {'book': 1, 'weight': 9}),
 ('Robert-Baratheon', 'Sansa-Stark', {'book': 1, 'weight': 26}),
 ('Robert-Baratheon', 'Stannis-Baratheon', {'book': 1, 'weight': 21}),
 ('Robert-Baratheon', 'Tommen-Baratheon', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Tyrion-Lannister', {'book': 1, 'weight': 18}),
 ('Robert-Baratheon', 'Varys', {'book': 1, 'weight': 36}),
 ('Robert-Baratheon', 'Vayon-Poole', {'book': 1, 'weight': 3}),
 ('Robert-Baratheon', 'Viserys-Targaryen', {'book': 1, 'weight': 7}),
 ('Aggo', 'Drogo', {'book': 1, 'weight': 6}),
 ('Aggo', 'Jhogo', {'book': 1, 'weight': 4}),
 ('Aggo', 'Jorah-Mormont', {'book': 1, 'weight': 5}),
 ('Aggo', 'Quaro', {'book': 1, 'weight': 3}),
 ('Aggo', 'Rakharo', {'book': 1, 'weight': 7}),
 ('Drogo', 'Cohollo', {'book': 1, 'weight': 9}),
 ('Drogo', 'Doreah', {'book': 1, 'weight': 5}),
 ('Drogo', 'Haggo', {'book': 1, 'weight': 9}),
 ('Drogo', 'Illyrio-Mopatis', {'book': 1, 'weight': 16}),
 ('Drogo', 'Irri', {'book': 1, 'weight': 9}),
 ('Drogo', 'Jhiqui', {'book': 1, 'weight': 5}),
 ('Drogo', 'Jhogo', {'book': 1, 'weight': 7}),
 ('Drogo', 'Jommo', {'book': 1, 'weight': 3}),
 ('Drogo', 'Jorah-Mormont', {'book': 1, 'weight': 16}),
 ('Drogo', 'Mirri-Maz-Duur', {'book': 1, 'weight': 12}),
 ('Drogo', 'Ogo', {'book': 1, 'weight': 11}),
 ('Drogo', 'Qotho', {'book': 1, 'weight': 13}),
 ('Drogo', 'Quaro', {'book': 1, 'weight': 3}),
 ('Drogo', 'Rakharo', {'book': 1, 'weight': 4}),
 ('Drogo', 'Rhaego', {'book': 1, 'weight': 5}),
 ('Drogo', 'Viserys-Targaryen', {'book': 1, 'weight': 19}),
 ('Jhogo', 'Irri', {'book': 1, 'weight': 7}),
 ('Jhogo', 'Jorah-Mormont', {'book': 1, 'weight': 5}),
 ('Jhogo', 'Mirri-Maz-Duur', {'book': 1, 'weight': 3}),
 ('Jorah-Mormont', 'Doreah', {'book': 1, 'weight': 3}),
 ('Jorah-Mormont', 'Illyrio-Mopatis', {'book': 1, 'weight': 7}),
 ('Jorah-Mormont', 'Irri', {'book': 1, 'weight': 4}),
 ('Jorah-Mormont', 'Jhiqui', {'book': 1, 'weight': 4}),
 ('Jorah-Mormont', 'Mirri-Maz-Duur', {'book': 1, 'weight': 5}),
 ('Jorah-Mormont', 'Qotho', {'book': 1, 'weight': 7}),
 ('Jorah-Mormont', 'Rhaegar-Targaryen', {'book': 1, 'weight': 5}),
 ('Jorah-Mormont', 'Viserys-Targaryen', {'book': 1, 'weight': 15}),
 ('Quaro', 'Qotho', {'book': 1, 'weight': 4}),
 ('Quaro', 'Rakharo', {'book': 1, 'weight': 6}),
 ('Rakharo', 'Haggo', {'book': 1, 'weight': 3}),
 ('Albett', 'Halder', {'book': 1, 'weight': 3}),
 ('Albett', 'Rast', {'book': 1, 'weight': 3}),
 ('Halder', 'Grenn', {'book': 1, 'weight': 6}),
 ('Halder', 'Pypar', {'book': 1, 'weight': 8}),
 ('Halder', 'Rast', {'book': 1, 'weight': 3}),
 ('Halder', 'Todder', {'book': 1, 'weight': 3}),
 ('Rast', 'Pypar', {'book': 1, 'weight': 4}),
 ('Grenn', 'Pypar', {'book': 1, 'weight': 27}),
 ('Grenn', 'Todder', {'book': 1, 'weight': 7}),
 ('Pypar', 'Todder', {'book': 1, 'weight': 8}),
 ('Tyrion-Lannister', 'Benjen-Stark', {'book': 1, 'weight': 8}),
 ('Tyrion-Lannister', 'Bran-Stark', {'book': 1, 'weight': 31}),
 ('Tyrion-Lannister', 'Bronn', {'book': 1, 'weight': 61}),
 ('Tyrion-Lannister', 'Brynden-Tully', {'book': 1, 'weight': 4}),
 ('Tyrion-Lannister', 'Catelyn-Stark', {'book': 1, 'weight': 49}),
 ('Tyrion-Lannister', 'Cersei-Lannister', {'book': 1, 'weight': 27}),
 ('Tyrion-Lannister', 'Chella', {'book': 1, 'weight': 5}),
 ('Tyrion-Lannister', 'Chiggen', {'book': 1, 'weight': 5}),
 ('Tyrion-Lannister', 'Conn', {'book': 1, 'weight': 6}),
 ('Tyrion-Lannister', 'Gregor-Clegane', {'book': 1, 'weight': 7}),
 ('Tyrion-Lannister', 'Gunthor-son-of-Gurn', {'book': 1, 'weight': 7}),
 ('Tyrion-Lannister', 'Joffrey-Baratheon', {'book': 1, 'weight': 13}),
 ('Tyrion-Lannister', 'Jyck', {'book': 1, 'weight': 6}),
 ('Tyrion-Lannister', 'Kevan-Lannister', {'book': 1, 'weight': 15}),
 ('Tyrion-Lannister', 'Kurleket', {'book': 1, 'weight': 5}),
 ('Tyrion-Lannister', 'Leo-Lefford', {'book': 1, 'weight': 4}),
 ('Tyrion-Lannister', 'Luwin', {'book': 1, 'weight': 10}),
 ('Tyrion-Lannister', 'Lysa-Arryn', {'book': 1, 'weight': 25}),
 ('Tyrion-Lannister', 'Marillion', {'book': 1, 'weight': 10}),
 ('Tyrion-Lannister', 'Mord', {'book': 1, 'weight': 20}),
 ('Tyrion-Lannister', 'Morrec', {'book': 1, 'weight': 5}),
 ('Tyrion-Lannister', 'Petyr-Baelish', {'book': 1, 'weight': 11}),
 ('Tyrion-Lannister', 'Renly-Baratheon', {'book': 1, 'weight': 4}),
 ('Tyrion-Lannister', 'Rickon-Stark', {'book': 1, 'weight': 4}),
 ('Tyrion-Lannister', 'Robb-Stark', {'book': 1, 'weight': 11}),
 ('Tyrion-Lannister', 'Robert-Arryn', {'book': 1, 'weight': 9}),
 ('Tyrion-Lannister', 'Rodrik-Cassel', {'book': 1, 'weight': 10}),
 ('Tyrion-Lannister', 'Sandor-Clegane', {'book': 1, 'weight': 5}),
 ('Tyrion-Lannister', 'Sansa-Stark', {'book': 1, 'weight': 3}),
 ('Tyrion-Lannister', 'Shae', {'book': 1, 'weight': 12}),
 ('Tyrion-Lannister', 'Shagga', {'book': 1, 'weight': 17}),
 ('Tyrion-Lannister', 'Theon-Greyjoy', {'book': 1, 'weight': 3}),
 ('Tyrion-Lannister', 'Timett', {'book': 1, 'weight': 3}),
 ('Tyrion-Lannister', 'Tommen-Baratheon', {'book': 1, 'weight': 3}),
 ('Tyrion-Lannister', 'Vardis-Egen', {'book': 1, 'weight': 9}),
 ('Tyrion-Lannister', 'Varys', {'book': 1, 'weight': 3}),
 ('Tyrion-Lannister', 'Willis-Wode', {'book': 1, 'weight': 4}),
 ('Tyrion-Lannister', 'Yoren', {'book': 1, 'weight': 10}),
 ('Alyn', 'Harwin', {'book': 1, 'weight': 6}),
 ('Alyn', 'Jory-Cassel', {'book': 1, 'weight': 8}),
 ('Alyn', 'Tomard', {'book': 1, 'weight': 3}),
 ('Harwin', 'Hullen', {'book': 1, 'weight': 3}),
 ('Harwin', 'Jory-Cassel', {'book': 1, 'weight': 4}),
 ('Jory-Cassel', 'Arya-Stark', {'book': 1, 'weight': 12}),
 ('Jory-Cassel', 'Bran-Stark', {'book': 1, 'weight': 11}),
 ('Jory-Cassel', 'Cersei-Lannister', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Heward', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Hullen', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Mordane', {'book': 1, 'weight': 3}),
 ('Jory-Cassel', 'Petyr-Baelish', {'book': 1, 'weight': 8}),
 ('Jory-Cassel', 'Robb-Stark', {'book': 1, 'weight': 9}),
 ('Jory-Cassel', 'Rodrik-Cassel', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Sansa-Stark', {'book': 1, 'weight': 9}),
 ('Jory-Cassel', 'Stannis-Baratheon', {'book': 1, 'weight': 3}),
 ('Jory-Cassel', 'Theon-Greyjoy', {'book': 1, 'weight': 3}),
 ('Jory-Cassel', 'Tomard', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Vayon-Poole', {'book': 1, 'weight': 5}),
 ('Jory-Cassel', 'Wyl-(guard)', {'book': 1, 'weight': 6}),
 ('Tomard', 'Arya-Stark', {'book': 1, 'weight': 6}),
 ('Tomard', 'Cayn', {'book': 1, 'weight': 6}),
 ('Tomard', 'Petyr-Baelish', {'book': 1, 'weight': 4}),
 ('Tomard', 'Sansa-Stark', {'book': 1, 'weight': 3}),
 ('Arya-Stark', 'Benjen-Stark', {'book': 1, 'weight': 3}),
 ('Arya-Stark', 'Bran-Stark', {'book': 1, 'weight': 14}),
 ('Arya-Stark', 'Catelyn-Stark', {'book': 1, 'weight': 5}),
 ('Arya-Stark', 'Cersei-Lannister', {'book': 1, 'weight': 12}),
 ('Arya-Stark', 'Desmond', {'book': 1, 'weight': 3}),
 ('Arya-Stark', 'Ilyn-Payne', {'book': 1, 'weight': 5}),
 ('Arya-Stark', 'Jeyne-Poole', {'book': 1, 'weight': 10}),
 ('Arya-Stark', 'Joffrey-Baratheon', {'book': 1, 'weight': 39}),
 ('Arya-Stark', 'Meryn-Trant', {'book': 1, 'weight': 4}),
 ('Arya-Stark', 'Mordane', {'book': 1, 'weight': 39}),
 ('Arya-Stark', 'Mycah', {'book': 1, 'weight': 18}),
 ('Arya-Stark', 'Myrcella-Baratheon', {'book': 1, 'weight': 13}),
 ('Arya-Stark', 'Petyr-Baelish', {'book': 1, 'weight': 3}),
 ('Arya-Stark', 'Rickon-Stark', {'book': 1, 'weight': 7}),
 ('Arya-Stark', 'Robb-Stark', {'book': 1, 'weight': 15}),
 ('Arya-Stark', 'Rodrik-Cassel', {'book': 1, 'weight': 3}),
 ('Arya-Stark', 'Sandor-Clegane', {'book': 1, 'weight': 7}),
 ('Arya-Stark', 'Sansa-Stark', {'book': 1, 'weight': 104}),
 ('Arya-Stark', 'Syrio-Forel', {'book': 1, 'weight': 20}),
 ('Arya-Stark', 'Tommen-Baratheon', {'book': 1, 'weight': 5}),
 ('Arya-Stark', 'Vayon-Poole', {'book': 1, 'weight': 4}),
 ('Arya-Stark', 'Yoren', {'book': 1, 'weight': 4}),
 ('Benjen-Stark', 'Bran-Stark', {'book': 1, 'weight': 6}),
 ('Benjen-Stark', 'Cersei-Lannister', {'book': 1, 'weight': 3}),
 ('Benjen-Stark', 'Jaremy-Rykker', {'book': 1, 'weight': 3}),
 ('Benjen-Stark', 'Luwin', {'book': 1, 'weight': 7}),
 ('Benjen-Stark', 'Mance-Rayder', {'book': 1, 'weight': 3}),
 ('Benjen-Stark', 'Robb-Stark', {'book': 1, 'weight': 7}),
 ('Benjen-Stark', 'Theon-Greyjoy', {'book': 1, 'weight': 4}),
 ('Benjen-Stark', 'Waymar-Royce', {'book': 1, 'weight': 3}),
 ('Benjen-Stark', 'Yoren', {'book': 1, 'weight': 4}),
 ('Bran-Stark', 'Catelyn-Stark', {'book': 1, 'weight': 18}),
 ('Bran-Stark', 'Cersei-Lannister', {'book': 1, 'weight': 6}),
 ('Bran-Stark', 'Hali', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Hallis-Mollen', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Hodor', {'book': 1, 'weight': 29}),
 ('Bran-Stark', 'Hullen', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Joffrey-Baratheon', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Joseth', {'book': 1, 'weight': 4}),
 ('Bran-Stark', 'Luwin', {'book': 1, 'weight': 65}),
 ('Bran-Stark', 'Nan', {'book': 1, 'weight': 17}),
 ('Bran-Stark', 'Osha', {'book': 1, 'weight': 12}),
 ('Bran-Stark', 'Petyr-Baelish', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Renly-Baratheon', {'book': 1, 'weight': 3}),
 ('Bran-Stark', 'Rickard-Karstark', {'book': 1, 'weight': 4}),
 ('Bran-Stark', 'Rickard-Stark', {'book': 1, 'weight': 4}),
 ('Bran-Stark', 'Rickon-Stark', {'book': 1, 'weight': 32}),
 ('Bran-Stark', 'Robb-Stark', {'book': 1, 'weight': 112}),
 ('Bran-Stark', 'Rodrik-Cassel', {'book': 1, 'weight': 6}),
 ('Bran-Stark', 'Sansa-Stark', {'book': 1, 'weight': 10}),
 ('Bran-Stark', 'Stiv', {'book': 1, 'weight': 4}),
 ('Bran-Stark', 'Theon-Greyjoy', {'book': 1, 'weight': 23}),
 ('Bran-Stark', 'Tommen-Baratheon', {'book': 1, 'weight': 5}),
 ('Bran-Stark', 'Yoren', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Bronn', {'book': 1, 'weight': 6}),
 ('Catelyn-Stark', 'Brynden-Tully', {'book': 1, 'weight': 16}),
 ('Catelyn-Stark', 'Cersei-Lannister', {'book': 1, 'weight': 12}),
 ('Catelyn-Stark', 'Colemon', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Donnel-Waynwood', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Edmure-Tully', {'book': 1, 'weight': 7}),
 ('Catelyn-Stark', 'Eon-Hunter', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Hallis-Mollen', {'book': 1, 'weight': 10}),
 ('Catelyn-Stark', 'Hoster-Tully', {'book': 1, 'weight': 6}),
 ('Catelyn-Stark', 'Joffrey-Baratheon', {'book': 1, 'weight': 4}),
 ('Catelyn-Stark', 'Jon-Umber-(Greatjon)', {'book': 1, 'weight': 4}),
 ('Catelyn-Stark', 'Luwin', {'book': 1, 'weight': 14}),
 ('Catelyn-Stark', 'Lysa-Arryn', {'book': 1, 'weight': 33}),
 ('Catelyn-Stark', 'Marillion', {'book': 1, 'weight': 6}),
 ('Catelyn-Stark', 'Masha-Heddle', {'book': 1, 'weight': 5}),
 ('Catelyn-Stark', 'Moreo-Tumitis', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Mya-Stone', {'book': 1, 'weight': 9}),
 ('Catelyn-Stark', 'Mychel-Redfort', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Nestor-Royce', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Petyr-Baelish', {'book': 1, 'weight': 22}),
 ('Catelyn-Stark', 'Rickard-Karstark', {'book': 1, 'weight': 6}),
 ('Catelyn-Stark', 'Rickon-Stark', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Robb-Stark', {'book': 1, 'weight': 49}),
 ('Catelyn-Stark', 'Robert-Arryn', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Rodrik-Cassel', {'book': 1, 'weight': 25}),
 ('Catelyn-Stark', 'Sansa-Stark', {'book': 1, 'weight': 9}),
 ('Catelyn-Stark', 'Stevron-Frey', {'book': 1, 'weight': 5}),
 ('Catelyn-Stark', 'Theon-Greyjoy', {'book': 1, 'weight': 9}),
 ('Catelyn-Stark', 'Tytos-Blackwood', {'book': 1, 'weight': 4}),
 ('Catelyn-Stark', 'Vardis-Egen', {'book': 1, 'weight': 5}),
 ('Catelyn-Stark', 'Varys', {'book': 1, 'weight': 10}),
 ('Catelyn-Stark', 'Walder-Frey', {'book': 1, 'weight': 13}),
 ('Catelyn-Stark', 'Wendel-Manderly', {'book': 1, 'weight': 3}),
 ('Catelyn-Stark', 'Willis-Wode', {'book': 1, 'weight': 5}),
 ('Cersei-Lannister', 'Arys-Oakheart', {'book': 1, 'weight': 3}),
 ('Cersei-Lannister', 'Barristan-Selmy', {'book': 1, 'weight': 12}),
 ('Cersei-Lannister', 'Boros-Blount', {'book': 1, 'weight': 9}),
 ('Cersei-Lannister', 'Ilyn-Payne', {'book': 1, 'weight': 4}),
 ('Cersei-Lannister', 'Janos-Slynt', {'book': 1, 'weight': 4}),
 ('Cersei-Lannister', 'Joffrey-Baratheon', {'book': 1, 'weight': 42}),
 ('Cersei-Lannister', 'Meryn-Trant', {'book': 1, 'weight': 4}),
 ('Cersei-Lannister', 'Mordane', {'book': 1, 'weight': 3}),
 ('Cersei-Lannister', 'Myrcella-Baratheon', {'book': 1, 'weight': 7}),
 ('Cersei-Lannister', 'Petyr-Baelish', {'book': 1, 'weight': 13}),
 ('Cersei-Lannister', 'Pycelle', {'book': 1, 'weight': 9}),
 ('Cersei-Lannister', 'Renly-Baratheon', {'book': 1, 'weight': 5}),
 ('Cersei-Lannister', 'Sandor-Clegane', {'book': 1, 'weight': 5}),
 ('Cersei-Lannister', 'Sansa-Stark', {'book': 1, 'weight': 29}),
 ('Cersei-Lannister', 'Stannis-Baratheon', {'book': 1, 'weight': 5}),
 ('Cersei-Lannister', 'Tommen-Baratheon', {'book': 1, 'weight': 4}),
 ('Cersei-Lannister', 'Varys', {'book': 1, 'weight': 19}),
 ('Cersei-Lannister', 'Vayon-Poole', {'book': 1, 'weight': 4}),
 ('Ilyn-Payne', 'Jeyne-Poole', {'book': 1, 'weight': 3}),
 ('Ilyn-Payne', 'Joffrey-Baratheon', {'book': 1, 'weight': 4}),
 ('Ilyn-Payne', 'Loras-Tyrell', {'book': 1, 'weight': 3}),
 ('Ilyn-Payne', 'Sansa-Stark', {'book': 1, 'weight': 9}),
 ('Ilyn-Payne', 'Varys', {'book': 1, 'weight': 5}),
 ('Jeyne-Poole', 'Loras-Tyrell', {'book': 1, 'weight': 4}),
 ('Jeyne-Poole', 'Mordane', {'book': 1, 'weight': 7}),
 ('Jeyne-Poole', 'Sansa-Stark', {'book': 1, 'weight': 27}),
 ('Joffrey-Baratheon', 'Barristan-Selmy', {'book': 1, 'weight': 6}),
 ('Joffrey-Baratheon', 'Boros-Blount', {'book': 1, 'weight': 3}),
 ('Joffrey-Baratheon', 'High-Septon-(fat_one)', {'book': 1, 'weight': 4}),
 ('Joffrey-Baratheon', 'Janos-Slynt', {'book': 1, 'weight': 4}),
 ('Joffrey-Baratheon', 'Loras-Tyrell', {'book': 1, 'weight': 3}),
 ('Joffrey-Baratheon', 'Meryn-Trant', {'book': 1, 'weight': 3}),
 ('Joffrey-Baratheon', 'Mordane', {'book': 1, 'weight': 9}),
 ('Joffrey-Baratheon', 'Mycah', {'book': 1, 'weight': 14}),
 ('Joffrey-Baratheon', 'Myrcella-Baratheon', {'book': 1, 'weight': 5}),
 ('Joffrey-Baratheon', 'Petyr-Baelish', {'book': 1, 'weight': 11}),
 ('Joffrey-Baratheon', 'Pycelle', {'book': 1, 'weight': 4}),
 ('Joffrey-Baratheon', 'Renly-Baratheon', {'book': 1, 'weight': 9}),
 ('Joffrey-Baratheon', 'Robb-Stark', {'book': 1, 'weight': 19}),
 ('Joffrey-Baratheon', 'Rodrik-Cassel', {'book': 1, 'weight': 9}),
 ('Joffrey-Baratheon', 'Sandor-Clegane', {'book': 1, 'weight': 24}),
 ('Joffrey-Baratheon', 'Sansa-Stark', {'book': 1, 'weight': 87}),
 ('Joffrey-Baratheon', 'Stannis-Baratheon', {'book': 1, 'weight': 7}),
 ('Joffrey-Baratheon', 'Tommen-Baratheon', {'book': 1, 'weight': 8}),
 ('Joffrey-Baratheon', 'Varys', {'book': 1, 'weight': 7}),
 ('Meryn-Trant', 'Barristan-Selmy', {'book': 1, 'weight': 3}),
 ('Meryn-Trant', 'Boros-Blount', {'book': 1, 'weight': 5}),
 ('Meryn-Trant', 'Sandor-Clegane', {'book': 1, 'weight': 4}),
 ('Meryn-Trant', 'Sansa-Stark', {'book': 1, 'weight': 5}),
 ('Meryn-Trant', 'Syrio-Forel', {'book': 1, 'weight': 5}),
 ('Mordane', 'Myrcella-Baratheon', {'book': 1, 'weight': 12}),
 ('Mordane', 'Petyr-Baelish', {'book': 1, 'weight': 3}),
 ('Mordane', 'Sansa-Stark', {'book': 1, 'weight': 43}),
 ('Mycah', 'Sandor-Clegane', {'book': 1, 'weight': 5}),
 ('Mycah', 'Sansa-Stark', {'book': 1, 'weight': 10}),
 ('Myrcella-Baratheon', 'Sansa-Stark', {'book': 1, 'weight': 8}),
 ('Myrcella-Baratheon', 'Tommen-Baratheon', {'book': 1, 'weight': 6}),
 ('Petyr-Baelish', 'Barristan-Selmy', {'book': 1, 'weight': 7}),
 ('Petyr-Baelish', 'Edmure-Tully', {'book': 1, 'weight': 4}),
 ('Petyr-Baelish', 'Gregor-Clegane', {'book': 1, 'weight': 3}),
 ('Petyr-Baelish', 'Janos-Slynt', {'book': 1, 'weight': 3}),
 ('Petyr-Baelish', 'Loras-Tyrell', {'book': 1, 'weight': 5}),
 ('Petyr-Baelish', 'Lysa-Arryn', {'book': 1, 'weight': 4}),
 ('Petyr-Baelish', 'Pycelle', {'book': 1, 'weight': 14}),
 ('Petyr-Baelish', 'Renly-Baratheon', {'book': 1, 'weight': 12}),
 ('Petyr-Baelish', 'Rodrik-Cassel', {'book': 1, 'weight': 7}),
 ('Petyr-Baelish', 'Sandor-Clegane', {'book': 1, 'weight': 3}),
 ('Petyr-Baelish', 'Sansa-Stark', {'book': 1, 'weight': 8}),
 ('Petyr-Baelish', 'Varys', {'book': 1, 'weight': 29}),
 ('Rickon-Stark', 'Luwin', {'book': 1, 'weight': 9}),
 ('Rickon-Stark', 'Robb-Stark', {'book': 1, 'weight': 20}),
 ('Rickon-Stark', 'Sansa-Stark', {'book': 1, 'weight': 8}),
 ('Robb-Stark', 'Brynden-Tully', {'book': 1, 'weight': 9}),
 ('Robb-Stark', 'Edmure-Tully', {'book': 1, 'weight': 5}),
 ('Robb-Stark', 'Galbart-Glover', {'book': 1, 'weight': 5}),
 ('Robb-Stark', 'Hallis-Mollen', {'book': 1, 'weight': 13}),
 ('Robb-Stark', 'Hodor', {'book': 1, 'weight': 5}),
 ('Robb-Stark', 'Hullen', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Jon-Umber-(Greatjon)', {'book': 1, 'weight': 8}),
 ('Robb-Stark', 'Luwin', {'book': 1, 'weight': 20}),
 ('Robb-Stark', 'Nan', {'book': 1, 'weight': 4}),
 ('Robb-Stark', 'Osha', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Renly-Baratheon', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Rickard-Karstark', {'book': 1, 'weight': 9}),
 ('Robb-Stark', 'Rodrik-Cassel', {'book': 1, 'weight': 15}),
 ('Robb-Stark', 'Roose-Bolton', {'book': 1, 'weight': 6}),
 ('Robb-Stark', 'Sansa-Stark', {'book': 1, 'weight': 13}),
 ('Robb-Stark', 'Stiv', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Theon-Greyjoy', {'book': 1, 'weight': 37}),
 ('Robb-Stark', 'Torrhen-Karstark', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Walder-Frey', {'book': 1, 'weight': 7}),
 ('Robb-Stark', 'Wendel-Manderly', {'book': 1, 'weight': 3}),
 ('Robb-Stark', 'Yoren', {'book': 1, 'weight': 3}),
 ('Rodrik-Cassel', 'Bronn', {'book': 1, 'weight': 4}),
 ('Rodrik-Cassel', 'Hullen', {'book': 1, 'weight': 3}),
 ('Rodrik-Cassel', 'Loras-Tyrell', {'book': 1, 'weight': 3}),
 ('Rodrik-Cassel', 'Luwin', {'book': 1, 'weight': 3}),
 ('Rodrik-Cassel', 'Marillion', {'book': 1, 'weight': 5}),
 ('Rodrik-Cassel', 'Theon-Greyjoy', {'book': 1, 'weight': 6}),
 ('Rodrik-Cassel', 'Willis-Wode', {'book': 1, 'weight': 7}),
 ('Sandor-Clegane', 'Balon-Swann', {'book': 1, 'weight': 3}),
 ('Sandor-Clegane', 'Barristan-Selmy', {'book': 1, 'weight': 3}),
 ('Sandor-Clegane', 'Gregor-Clegane', {'book': 1, 'weight': 11}),
 ('Sandor-Clegane', 'Loras-Tyrell', {'book': 1, 'weight': 4}),
 ('Sandor-Clegane', 'Renly-Baratheon', {'book': 1, 'weight': 7}),
 ('Sandor-Clegane', 'Sansa-Stark', {'book': 1, 'weight': 23}),
 ('Sansa-Stark', 'Barristan-Selmy', {'book': 1, 'weight': 3}),
 ('Sansa-Stark', 'Beric-Dondarrion', {'book': 1, 'weight': 4}),
 ('Sansa-Stark', 'Boros-Blount', {'book': 1, 'weight': 6}),
 ('Sansa-Stark', 'Gregor-Clegane', {'book': 1, 'weight': 5}),
 ('Sansa-Stark', 'Janos-Slynt', {'book': 1, 'weight': 3}),
 ('Sansa-Stark', 'Loras-Tyrell', {'book': 1, 'weight': 14}),
 ('Sansa-Stark', 'Lyanna-Stark', {'book': 1, 'weight': 4}),
 ('Sansa-Stark', 'Maegor-I-Targaryen', {'book': 1, 'weight': 4}),
 ('Sansa-Stark', 'Pycelle', {'book': 1, 'weight': 8}),
 ('Sansa-Stark', 'Renly-Baratheon', {'book': 1, 'weight': 5}),
 ('Sansa-Stark', 'Rhaegar-Targaryen', {'book': 1, 'weight': 3}),
 ('Sansa-Stark', 'Stannis-Baratheon', {'book': 1, 'weight': 3}),
 ('Sansa-Stark', 'Varys', {'book': 1, 'weight': 4}),
 ('Tommen-Baratheon', 'Luwin', {'book': 1, 'weight': 3}),
 ('Balon-Swann', 'Renly-Baratheon', {'book': 1, 'weight': 3}),
 ('Renly-Baratheon', 'Barristan-Selmy', {'book': 1, 'weight': 13}),
 ('Renly-Baratheon', 'Cayn', {'book': 1, 'weight': 3}),
 ('Renly-Baratheon', 'Loras-Tyrell', {'book': 1, 'weight': 5}),
 ('Renly-Baratheon', 'Pycelle', {'book': 1, 'weight': 7}),
 ('Renly-Baratheon', 'Stannis-Baratheon', {'book': 1, 'weight': 19}),
 ('Renly-Baratheon', 'Varys', {'book': 1, 'weight': 9}),
 ('Barristan-Selmy', 'Boros-Blount', {'book': 1, 'weight': 3}),
 ('Barristan-Selmy', 'Pycelle', {'book': 1, 'weight': 8}),
 ('Barristan-Selmy', 'Varys', {'book': 1, 'weight': 9}),
 ('Pycelle', 'Gregor-Clegane', {'book': 1, 'weight': 3}),
 ('Pycelle', 'Janos-Slynt', {'book': 1, 'weight': 3}),
 ('Pycelle', 'Stannis-Baratheon', {'book': 1, 'weight': 3}),
 ('Pycelle', 'Varys', {'book': 1, 'weight': 17}),
 ('Varys', 'Stannis-Baratheon', {'book': 1, 'weight': 5}),
 ('Jaremy-Rykker', 'Jafer-Flowers', {'book': 1, 'weight': 3}),
 ('Luwin', 'Hallis-Mollen', {'book': 1, 'weight': 4}),
 ('Luwin', 'Hodor', {'book': 1, 'weight': 10}),
 ('Luwin', 'Hullen', {'book': 1, 'weight': 3}),
 ('Luwin', 'Joseth', {'book': 1, 'weight': 3}),
 ('Luwin', 'Nan', {'book': 1, 'weight': 4}),
 ('Luwin', 'Osha', {'book': 1, 'weight': 16}),
 ('Luwin', 'Rickard-Karstark', {'book': 1, 'weight': 3}),
 ('Luwin', 'Theon-Greyjoy', {'book': 1, 'weight': 10}),
 ('Theon-Greyjoy', 'Brynden-Tully', {'book': 1, 'weight': 6}),
 ('Theon-Greyjoy', 'Hallis-Mollen', {'book': 1, 'weight': 7}),
 ('Theon-Greyjoy', 'Jon-Umber-(Greatjon)', {'book': 1, 'weight': 5}),
 ('Theon-Greyjoy', 'Walder-Frey', {'book': 1, 'weight': 4}),
 ('Waymar-Royce', 'Gared', {'book': 1, 'weight': 13}),
 ('Waymar-Royce', 'Will-(prologue)', {'book': 1, 'weight': 18}),
 ('Beric-Dondarrion', 'Gregor-Clegane', {'book': 1, 'weight': 6}),
 ('Beric-Dondarrion', 'Loras-Tyrell', {'book': 1, 'weight': 5}),
 ('Beric-Dondarrion', 'Thoros-of-Myr', {'book': 1, 'weight': 5}),
 ('Gregor-Clegane', 'Loras-Tyrell', {'book': 1, 'weight': 10}),
 ('Gregor-Clegane', 'Marq-Piper', {'book': 1, 'weight': 6}),
 ('Loras-Tyrell', 'Mace-Tyrell', {'book': 1, 'weight': 3}),
 ('Hodor', 'Nan', {'book': 1, 'weight': 8}),
 ('Rickard-Karstark', 'Galbart-Glover', {'book': 1, 'weight': 4}),
 ('Rickard-Karstark', 'Jon-Umber-(Greatjon)', {'book': 1, 'weight': 7}),
 ('Rickard-Karstark', 'Maege-Mormont', {'book': 1, 'weight': 3}),
 ('Rickard-Karstark', 'Roose-Bolton', {'book': 1, 'weight': 3}),
 ('Bronn', 'Chiggen', {'book': 1, 'weight': 8}),
 ('Bronn', 'Marillion', {'book': 1, 'weight': 4}),
 ('Bronn', 'Shae', {'book': 1, 'weight': 3}),
 ('Bronn', 'Shagga', {'book': 1, 'weight': 3}),
 ('Bronn', 'Vardis-Egen', {'book': 1, 'weight': 11}),
 ('Bronn', 'Willis-Wode', {'book': 1, 'weight': 5}),
 ('Chiggen', 'Willis-Wode', {'book': 1, 'weight': 3}),
 ('Marillion', 'Willis-Wode', {'book': 1, 'weight': 4}),
 ('Shagga', 'Conn', {'book': 1, 'weight': 9}),
 ('Shagga', 'Dolf', {'book': 1, 'weight': 7}),
 ('Shagga', 'Timett', {'book': 1, 'weight': 4}),
 ('Shagga', 'Ulf-son-of-Umar', {'book': 1, 'weight': 4}),
 ('Vardis-Egen', 'Colemon', {'book': 1, 'weight': 4}),
 ('Vardis-Egen', 'Eon-Hunter', {'book': 1, 'weight': 3}),
 ('Vardis-Egen', 'Lysa-Arryn', {'book': 1, 'weight': 5}),
 ('Brynden-Tully', 'Edmure-Tully', {'book': 1, 'weight': 3}),
 ('Brynden-Tully', 'Hoster-Tully', {'book': 1, 'weight': 5}),
 ('Brynden-Tully', 'Lysa-Arryn', {'book': 1, 'weight': 10}),
 ('Brynden-Tully', 'Nestor-Royce', {'book': 1, 'weight': 3}),
 ('Brynden-Tully', 'Walder-Frey', {'book': 1, 'weight': 3}),
 ('Edmure-Tully', 'Hoster-Tully', {'book': 1, 'weight': 7}),
 ('Edmure-Tully', 'Karyl-Vance', {'book': 1, 'weight': 4}),
 ('Edmure-Tully', 'Lysa-Arryn', {'book': 1, 'weight': 5}),
 ('Edmure-Tully', 'Marq-Piper', {'book': 1, 'weight': 3}),
 ('Edmure-Tully', 'Tytos-Blackwood', {'book': 1, 'weight': 3}),
 ('Hoster-Tully', 'Lysa-Arryn', {'book': 1, 'weight': 3}),
 ('Lysa-Arryn', 'Eon-Hunter', {'book': 1, 'weight': 3}),
 ('Lysa-Arryn', 'Lyn-Corbray', {'book': 1, 'weight': 3}),
 ('Lysa-Arryn', 'Robert-Arryn', {'book': 1, 'weight': 8}),
 ('Lysa-Arryn', 'Stannis-Baratheon', {'book': 1, 'weight': 4}),
 ('Walder-Frey', 'Danwell-Frey', {'book': 1, 'weight': 3}),
 ('Walder-Frey', 'Stevron-Frey', {'book': 1, 'weight': 3}),
 ('Jon-Umber-(Greatjon)', 'Galbart-Glover', {'book': 1, 'weight': 4}),
 ('Jon-Umber-(Greatjon)', 'Maege-Mormont', {'book': 1, 'weight': 5}),
 ('Jon-Umber-(Greatjon)', 'Roose-Bolton', {'book': 1, 'weight': 3}),
 ('Tytos-Blackwood', 'Jonos-Bracken', {'book': 1, 'weight': 3}),
 ('Clement-Piper', 'Karyl-Vance', {'book': 1, 'weight': 4}),
 ('Karyl-Vance', 'Marq-Piper', {'book': 1, 'weight': 3}),
 ('Cohollo', 'Haggo', {'book': 1, 'weight': 7}),
 ('Cohollo', 'Qotho', {'book': 1, 'weight': 6}),
 ('Haggo', 'Mirri-Maz-Duur', {'book': 1, 'weight': 3}),
 ('Haggo', 'Qotho', {'book': 1, 'weight': 11}),
 ('Qotho', 'Mirri-Maz-Duur', {'book': 1, 'weight': 9}),
 ('Conn', 'Coratt', {'book': 1, 'weight': 5}),
 ('Doreah', 'Irri', {'book': 1, 'weight': 14}),
 ('Doreah', 'Jhiqui', {'book': 1, 'weight': 11}),
 ('Doreah', 'Viserys-Targaryen', {'book': 1, 'weight': 3}),
 ('Illyrio-Mopatis', 'Irri', {'book': 1, 'weight': 3}),
 ('Illyrio-Mopatis', 'Viserys-Targaryen', {'book': 1, 'weight': 14}),
 ('Irri', 'Jhiqui', {'book': 1, 'weight': 14}),
 ('Irri', 'Viserys-Targaryen', {'book': 1, 'weight': 5}),
 ('Rhaegar-Targaryen', 'Viserys-Targaryen', {'book': 1, 'weight': 5}),
 ('Danwell-Frey', 'Hosteen-Frey', {'book': 1, 'weight': 3}),
 ('Danwell-Frey', 'Jared-Frey', {'book': 1, 'weight': 3}),
 ('Hosteen-Frey', 'Jared-Frey', {'book': 1, 'weight': 3}),
 ('Daryn-Hornwood', 'Torrhen-Karstark', {'book': 1, 'weight': 3}),
 ('Jommo', 'Ogo', {'book': 1, 'weight': 3}),
 ('Ogo', 'Fogo', {'book': 1, 'weight': 4}),
 ('Galbart-Glover', 'Roose-Bolton', {'book': 1, 'weight': 3}),
 ('Wyl-(guard)', 'Heward', {'book': 1, 'weight': 3}),
 ('Gared', 'Will-(prologue)', {'book': 1, 'weight': 12}),
 ('Jyck', 'Morrec', {'book': 1, 'weight': 5}),
 ('Mace-Tyrell', 'Paxter-Redwyne', {'book': 1, 'weight': 3})]
# 简单可视化
plt.figure(figsize=(10, 9))
nx.draw_networkx(G_book1)
<IPython.core.display.Javascript object>

4.3 网络分析

4.3.1 查看最重要的节点

4.3.1.1 Degree Centrality

# degree centrality

# 计算每个网络的 degree centrality
deg_cent_list = [nx.degree_centrality(G_book) for G_book in G_books]

# 将计算结果构建成Series
deg_cent_series_list = [pd.Series(deg_cent) for deg_cent in deg_cent_list]
top_n = 10

for i, deg_cent_series in enumerate(deg_cent_series_list):
    print('第{}本书最重要的{}个人物:'.format(i + 1, top_n))
    # 取出每个图的 top_n 个节点
    top_characters = deg_cent_series.sort_values(ascending=False)[:top_n]
    print(top_characters)

#     plt.figure(figsize=(10, 8))
#     top_characters.plot(kind='bar', title='第{}本书'.format(i + 1))
#     plt.tight_layout()
    print()
第1本书最重要的10个人物:
Eddard-Stark         0.354839
Robert-Baratheon     0.268817
Tyrion-Lannister     0.247312
Catelyn-Stark        0.231183
Jon-Snow             0.198925
Sansa-Stark          0.188172
Robb-Stark           0.188172
Bran-Stark           0.172043
Joffrey-Baratheon    0.161290
Cersei-Lannister     0.161290
dtype: float64

第2本书最重要的10个人物:
Tyrion-Lannister     0.205426
Joffrey-Baratheon    0.182171
Cersei-Lannister     0.166667
Arya-Stark           0.155039
Stannis-Baratheon    0.143411
Robb-Stark           0.135659
Catelyn-Stark        0.127907
Theon-Greyjoy        0.124031
Renly-Baratheon      0.120155
Bran-Stark           0.116279
dtype: float64

第3本书最重要的10个人物:
Tyrion-Lannister     0.195364
Jon-Snow             0.172185
Joffrey-Baratheon    0.165563
Robb-Stark           0.162252
Sansa-Stark          0.158940
Jaime-Lannister      0.149007
Cersei-Lannister     0.125828
Catelyn-Stark        0.125828
Arya-Stark           0.122517
Stannis-Baratheon    0.102649
dtype: float64

第4本书最重要的10个人物:
Jaime-Lannister      0.234432
Cersei-Lannister     0.219780
Brienne-of-Tarth     0.102564
Tyrion-Lannister     0.095238
Margaery-Tyrell      0.091575
Tommen-Baratheon     0.087912
Sansa-Stark          0.087912
Samwell-Tarly        0.073260
Stannis-Baratheon    0.073260
Petyr-Baelish        0.069597
dtype: float64

第5本书最重要的10个人物:
Jon-Snow              0.196203
Daenerys-Targaryen    0.183544
Stannis-Baratheon     0.148734
Theon-Greyjoy         0.104430
Tyrion-Lannister      0.104430
Cersei-Lannister      0.088608
Barristan-Selmy       0.079114
Hizdahr-zo-Loraq      0.069620
Asha-Greyjoy          0.056962
Melisandre            0.053797
dtype: float64
plt.close()

4.3.1.2 Closeness Centrality

# closeness centrality

# 计算每个网络的 closeness centrality
clo_cent_list = [nx.closeness_centrality(G_book) for G_book in G_books]

# 将计算结果构建成Series
clo_cent_series_list = [pd.Series(clo_cent) for clo_cent in clo_cent_list]
top_n = 10

for i, clo_cent_series in enumerate(clo_cent_series_list):
    print('第{}本书最重要的{}个人物:'.format(i + 1, top_n))
    # 取出每个图的 top_n 个节点
    top_characters = clo_cent_series.sort_values(ascending=False)[:top_n]
    print(top_characters)

#     plt.figure(figsize=(10, 8))
#     top_characters.plot(kind='bar', title='第{}本书'.format(i + 1))
#     plt.tight_layout()
    print()
第1本书最重要的10个人物:
Eddard-Stark         0.563636
Robert-Baratheon     0.545455
Tyrion-Lannister     0.510989
Catelyn-Stark        0.505435
Robb-Stark           0.497326
Jon-Snow             0.493369
Sansa-Stark          0.489474
Bran-Stark           0.486911
Cersei-Lannister     0.484375
Joffrey-Baratheon    0.480620
dtype: float64

第2本书最重要的10个人物:
Robb-Stark           0.477778
Eddard-Stark         0.457447
Robert-Baratheon     0.448696
Jaime-Lannister      0.447140
Tyrion-Lannister     0.444062
Joffrey-Baratheon    0.438776
Arya-Stark           0.435076
Catelyn-Stark        0.433613
Sansa-Stark          0.430718
Cersei-Lannister     0.430718
dtype: float64

第3本书最重要的10个人物:
Joffrey-Baratheon    0.474097
Tyrion-Lannister     0.457576
Arya-Stark           0.442815
Robb-Stark           0.440233
Stannis-Baratheon    0.438953
Robert-Baratheon     0.438316
Jaime-Lannister      0.437048
Jon-Snow             0.433908
Eddard-Stark         0.426554
Sansa-Stark          0.424754
dtype: float64

第4本书最重要的10个人物:
Cersei-Lannister     0.420000
Tyrion-Lannister     0.396226
Tywin-Lannister      0.388889
Jaime-Lannister      0.382889
Tommen-Baratheon     0.377593
Sansa-Stark          0.370421
Stannis-Baratheon    0.369418
Pycelle              0.359684
Brienne-of-Tarth     0.355469
Robert-Baratheon     0.351804
dtype: float64

第5本书最重要的10个人物:
Stannis-Baratheon     0.432285
Tyrion-Lannister      0.402548
Robert-Baratheon      0.400507
Cersei-Lannister      0.398487
Eddard-Stark          0.376190
Daenerys-Targaryen    0.364055
Myrcella-Baratheon    0.359909
Val                   0.359091
Tywin-Lannister       0.358683
Asha-Greyjoy          0.357871
dtype: float64

4.3.1.3 Betweenness Centrality

# betweenness centrality

# 计算每个网络的 betweenness centrality
btw_cent_list = [nx.betweenness_centrality(G_book) for G_book in G_books]

# 将计算结果构建成Series
btw_cent_series_list = [pd.Series(btw_cent) for btw_cent in btw_cent_list]
top_n = 10

for i, btw_cent_series in enumerate(btw_cent_series_list):
    print('第{}本书最重要的{}个人物:'.format(i + 1, top_n))
    # 取出每个图的 top_n 个节点
    top_characters = btw_cent_series.sort_values(ascending=False)[:top_n]
    print(top_characters)

#     plt.figure(figsize=(10, 8))
#     top_characters.plot(kind='bar', title='第{}本书'.format(i + 1))
#     plt.tight_layout()
    print()
第1本书最重要的10个人物:
Eddard-Stark          0.269604
Robert-Baratheon      0.214030
Tyrion-Lannister      0.190212
Jon-Snow              0.171581
Catelyn-Stark         0.151395
Daenerys-Targaryen    0.086270
Robb-Stark            0.072984
Drogo                 0.064812
Bran-Stark            0.055800
Sansa-Stark           0.037145
dtype: float64

第2本书最重要的10个人物:
Arya-Stark           0.188112
Jon-Snow             0.174440
Robb-Stark           0.164941
Tyrion-Lannister     0.155324
Robert-Baratheon     0.153744
Theon-Greyjoy        0.144395
Stannis-Baratheon    0.119514
Bran-Stark           0.113235
Catelyn-Stark        0.111044
Joffrey-Baratheon    0.090782
dtype: float64

第3本书最重要的10个人物:
Jon-Snow              0.223829
Robert-Baratheon      0.166435
Robb-Stark            0.162321
Tyrion-Lannister      0.154091
Joffrey-Baratheon     0.141891
Daenerys-Targaryen    0.136491
Jaime-Lannister       0.124491
Stannis-Baratheon     0.109017
Arya-Stark            0.094787
Sansa-Stark           0.089603
dtype: float64

第4本书最重要的10个人物:
Stannis-Baratheon     0.276306
Cersei-Lannister      0.275480
Jaime-Lannister       0.242819
Balon-Greyjoy         0.190597
Sansa-Stark           0.152754
Samwell-Tarly         0.140178
Brienne-of-Tarth      0.109834
Arya-Stark            0.108119
Myrcella-Baratheon    0.107331
Tyrion-Lannister      0.091159
dtype: float64

第5本书最重要的10个人物:
Stannis-Baratheon     0.452831
Daenerys-Targaryen    0.295946
Jon-Snow              0.244849
Tyrion-Lannister      0.209616
Robert-Baratheon      0.177169
Cersei-Lannister      0.155657
Theon-Greyjoy         0.109959
Asha-Greyjoy          0.089418
Eddard-Stark          0.073434
Doran-Martell         0.052868
dtype: float64

4.3.1.4 Page Rank

# page rank

# 计算每个网络的 page rank
page_rank_list = [nx.pagerank(G_book) for G_book in G_books]

# 将计算结果构建成Series
page_rank_series_list = [pd.Series(page_rank) for page_rank in page_rank_list]
top_n = 10

for i, page_rank_series in enumerate(page_rank_series_list):
    print('第{}本书最重要的{}个人物:'.format(i + 1, top_n))
    # 取出每个图的 top_n 个节点
    top_characters = page_rank_series.sort_values(ascending=False)[:top_n]
    print(top_characters)

#     plt.figure(figsize=(10, 8))
#     top_characters.plot(kind='bar', title='第{}本书'.format(i + 1))
#     plt.tight_layout()
    print()
第1本书最重要的10个人物:
Eddard-Stark          0.072362
Robert-Baratheon      0.048494
Jon-Snow              0.047708
Tyrion-Lannister      0.043676
Catelyn-Stark         0.034667
Bran-Stark            0.029770
Robb-Stark            0.029214
Daenerys-Targaryen    0.027099
Sansa-Stark           0.026945
Cersei-Lannister      0.021620
dtype: float64

第2本书最重要的10个人物:
Tyrion-Lannister     0.046869
Joffrey-Baratheon    0.033514
Bran-Stark           0.032065
Arya-Stark           0.029019
Stannis-Baratheon    0.028821
Jon-Snow             0.028401
Theon-Greyjoy        0.027660
Cersei-Lannister     0.027441
Robb-Stark           0.023135
Renly-Baratheon      0.022946
dtype: float64

第3本书最重要的10个人物:
Jon-Snow              0.037954
Tyrion-Lannister      0.036393
Robb-Stark            0.027922
Jaime-Lannister       0.027516
Joffrey-Baratheon     0.025867
Sansa-Stark           0.025732
Daenerys-Targaryen    0.022517
Samwell-Tarly         0.019644
Arya-Stark            0.019424
Catelyn-Stark         0.018832
dtype: float64

第4本书最重要的10个人物:
Cersei-Lannister     0.057348
Jaime-Lannister      0.049880
Brienne-of-Tarth     0.024111
Samwell-Tarly        0.023794
Tommen-Baratheon     0.019658
Arya-Stark           0.019151
Margaery-Tyrell      0.018867
Victarion-Greyjoy    0.017702
Euron-Greyjoy        0.016262
Aeron-Greyjoy        0.015859
dtype: float64

第5本书最重要的10个人物:
Jon-Snow              0.059572
Daenerys-Targaryen    0.044292
Stannis-Baratheon     0.034819
Tyrion-Lannister      0.028882
Theon-Greyjoy         0.025041
Hizdahr-zo-Loraq      0.016476
Cersei-Lannister      0.015888
Barristan-Selmy       0.015527
Ramsay-Snow           0.014337
Quentyn-Martell       0.014037
dtype: float64

4.3.2 各指标的相关性

cor_df = pd.DataFrame(columns=['Degree Centrality', 'Closeness Centrality', 'Betweenness Centrality', 'Page Rank'])
cor_df['Degree Centrality'] = pd.Series(nx.degree_centrality(G_book1))
cor_df['Closeness Centrality'] = pd.Series(nx.closeness_centrality(G_book1))
cor_df['Betweenness Centrality'] = pd.Series(nx.betweenness_centrality(G_book1))
cor_df['Page Rank'] = pd.Series(nx.pagerank(G_book1))
cor_df.head()
Degree Centrality Closeness Centrality Betweenness Centrality Page Rank
Addam-Marbrand 0.010753 0.323478 0.000000 0.001276
Aegon-I-Targaryen 0.010753 0.376518 0.000000 0.001254
Aemon-Targaryen-(Maester-Aemon) 0.037634 0.336957 0.010845 0.005812
Aerys-II-Targaryen 0.032258 0.385892 0.000482 0.003040
Aggo 0.032258 0.292913 0.000073 0.003123
cor_df.corr()
Degree Centrality Closeness Centrality Betweenness Centrality Page Rank
Degree Centrality 1.000000 0.796965 0.838933 0.949258
Closeness Centrality 0.796965 1.000000 0.578166 0.686706
Betweenness Centrality 0.838933 0.578166 1.000000 0.935354
Page Rank 0.949258 0.686706 0.935354 1.000000

4.3.3 人物重要性的趋势

trend_df = pd.DataFrame(columns=['Book1', 'Book2', 'Book3', 'Book4', 'Book5'])
trend_df['Book1'] = pd.Series(nx.degree_centrality(G_book1))
trend_df['Book2'] = pd.Series(nx.degree_centrality(G_book2))
trend_df['Book3'] = pd.Series(nx.degree_centrality(G_book3))
trend_df['Book4'] = pd.Series(nx.degree_centrality(G_book4))
trend_df['Book5'] = pd.Series(nx.degree_centrality(G_book5))
trend_df.fillna(0, inplace=True)
trend_df.head()
Book1 Book2 Book3 Book4 Book5
Addam-Marbrand 0.010753 0.000000 0.026490 0.014652 0.000000
Aegon-I-Targaryen 0.010753 0.019380 0.009934 0.000000 0.003165
Aemon-Targaryen-(Maester-Aemon) 0.037634 0.023256 0.059603 0.025641 0.015823
Aerys-II-Targaryen 0.032258 0.019380 0.029801 0.032967 0.009494
Aggo 0.032258 0.019380 0.006623 0.000000 0.018987
# 第1本书中最重要top10人物的趋势
top_10_from_book1 = trend_df.sort_values('Book1', ascending=False)[:10]
top_10_from_book1
Book1 Book2 Book3 Book4 Book5
Eddard-Stark 0.354839 0.085271 0.052980 0.029304 0.044304
Robert-Baratheon 0.268817 0.100775 0.086093 0.047619 0.047468
Tyrion-Lannister 0.247312 0.205426 0.195364 0.095238 0.104430
Catelyn-Stark 0.231183 0.127907 0.125828 0.040293 0.003165
Jon-Snow 0.198925 0.108527 0.172185 0.040293 0.196203
Sansa-Stark 0.188172 0.104651 0.158940 0.087912 0.009494
Robb-Stark 0.188172 0.135659 0.162252 0.025641 0.031646
Bran-Stark 0.172043 0.116279 0.056291 0.014652 0.037975
Cersei-Lannister 0.161290 0.166667 0.125828 0.219780 0.088608
Joffrey-Baratheon 0.161290 0.182171 0.165563 0.047619 0.009494
top_10_from_book1.T.plot(figsize=(10, 8))
plt.tight_layout()
<IPython.core.display.Javascript object>

4.3.4 网络可视化

plt.figure(figsize=(15, 10))

# 节点颜色由节点的度决定
node_color = [G_book1.degree(v) for v in G_book1]

# 节点的大小由degree centrality决定
node_size = [10000 * nx.degree_centrality(G_book1)[v] for v in G_book1]

# 边的宽度由权重决定
edge_width = [0.2 * G_book1[u][v]['weight'] for u, v in G_book1.edges()]

# 使用spring布局
pos=nx.spring_layout(G_book1)

nx.draw_networkx(G_book1, pos, node_size=node_size, 
                 node_color=node_color, alpha=0.7, 
                 with_labels=False, width=edge_width)

# 取出第一本书的top10人物
top10_in_book1 = top_10_from_book1.index.values.tolist()
# 构建label
labels = {role: role for role in top10_in_book1}

# 给网络添加label
nx.draw_networkx_labels(G_book1, pos, labels=labels, font_size=10)

plt.axis('off')
plt.tight_layout()
<IPython.core.display.Javascript object>

5. 项目总结