diff --git "a/processing.ipynb" "b/processing.ipynb"
--- "a/processing.ipynb"
+++ "b/processing.ipynb"
@@ -1 +1 @@
-{"cells":[{"cell_type":"code","execution_count":2,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EvTuwbs9r4aw","executionInfo":{"status":"ok","timestamp":1709307950772,"user_tz":300,"elapsed":18530,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"e4c04ebf-fb5a-4990-da77-a450598b3df7"},"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n","/content/drive/MyDrive/Colab_Notebooks/Marvel_network\n"]}],"source":["import numpy as np\n","import pandas as pd\n","import networkx as nx\n","import matplotlib.pyplot as plt\n","from tqdm import trange\n","from google.colab import drive\n","drive.mount('/content/drive')\n","%cd /content/drive/MyDrive/Colab_Notebooks/Marvel_network"]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QHxuWhh8r4ay","executionInfo":{"status":"ok","timestamp":1709308038937,"user_tz":300,"elapsed":1658,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"ff562e1f-3640-49d7-bcf1-9f69c9f127ad"},"outputs":[{"output_type":"stream","name":"stdout","text":["96104\n","574467\n"]}],"source":["# Read datasets\n","elements=pd.read_csv('source_data/nodes.csv')\n","hero=elements[elements['type']=='hero']['node']\n","comic=elements[elements['type']=='comic']['node']\n","hero_comic=pd.read_csv('source_data/edges.csv')\n","print(len(hero_comic))\n","hero_hero=pd.read_csv('source_data/hero-network.csv')\n","print(len(hero_hero))"]},{"cell_type":"code","execution_count":5,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"KFLbMoter4ay","executionInfo":{"status":"ok","timestamp":1709308042509,"user_tz":300,"elapsed":306,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"f7898146-fca2-4056-b846-1151f5d34583"},"outputs":[{"output_type":"stream","name":"stdout","text":["82593\n","424270\n"]}],"source":["# Create hero and comic lists\n","hero=list((set(hero_hero['hero1']).union(\n"," set(hero_hero['hero2']))).intersection(\n"," set(hero_comic['hero'])).intersection(\n"," set(hero)\n"," ))\n","\n","comic=list(set(hero_comic['comic']).intersection(set(comic)))\n","\n","# Delete edges containing unknown hero/comic\n","hero_comic=hero_comic[hero_comic['comic'].isin(comic)]\n","hero_comic=hero_comic[hero_comic['hero'].isin(hero)]\n","print(len(hero_comic))\n","\n","hero_hero=hero_hero[hero_hero['hero1'].isin(hero)]\n","hero_hero=hero_hero[hero_hero['hero2'].isin(hero)]\n","print(len(hero_hero))"]},{"cell_type":"code","execution_count":6,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_BrGgTMMr4az","executionInfo":{"status":"ok","timestamp":1709308185730,"user_tz":300,"elapsed":140840,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"8b2f9eea-5144-48e7-b33c-f17e8525610d"},"outputs":[{"output_type":"stream","name":"stderr","text":["100%|██████████| 6282/6282 [02:20<00:00, 44.62it/s]\n"]}],"source":["# Determine in which comics the hero pairs meet\n","hero_hero_comic=pd.DataFrame(columns=['hero1','hero2','comic'])\n","for i in trange(len(hero)):\n"," hero1=hero[i]\n"," pair1=hero_comic[hero_comic['hero']==hero1]\n"," hero_comic=hero_comic[hero_comic['hero']!=hero1]\n"," pair2=hero_comic[hero_comic['comic'].isin(pair1['comic'])]\n"," pair2.columns=['hero2', 'comic']\n"," pair2.insert(0,'hero1',hero1,True)\n"," hero_hero_comic=pd.concat([hero_hero_comic,pair2])"]},{"cell_type":"code","execution_count":7,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gBvjnLn0r4az","executionInfo":{"status":"ok","timestamp":1709308287123,"user_tz":300,"elapsed":101398,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"c6757189-dd0f-4f67-9e92-709dcd87be0b"},"outputs":[{"output_type":"stream","name":"stderr","text":["100%|██████████| 142289/142289 [00:25<00:00, 5543.05it/s]\n","100%|██████████| 183645/183645 [01:15<00:00, 2442.47it/s]\n"]}],"source":["def flatten_list(matrix):\n"," flat_list = []\n"," for row in matrix:\n"," flat_list += row\n"," return flat_list\n","\n","# List unique pairs\n","existing_pairs=hero_hero_comic[['hero1','hero2']].drop_duplicates()\n","existing_pairs=[[(existing_pairs.iloc[i]['hero1'],existing_pairs.iloc[i]['hero2']),\n"," (existing_pairs.iloc[i]['hero2'],existing_pairs.iloc[i]['hero1']) ]\n"," for i in trange(len(existing_pairs))]\n","existing_pairs=flatten_list(existing_pairs)\n","\n","hero_hero=hero_hero.groupby(['hero1','hero2']).size().reset_index(name='counts')\n","adding_pairs=hero_hero.drop_duplicates()\n","adding_pairs=[(adding_pairs.iloc[i]['hero1'],adding_pairs.iloc[i]['hero2'])\n"," for i in trange(len(adding_pairs))\n"," if adding_pairs.iloc[i]['hero1']!=adding_pairs.iloc[i]['hero2']]\n"]},{"cell_type":"code","execution_count":8,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":424},"id":"A07g1IEzr4az","executionInfo":{"status":"ok","timestamp":1709308287288,"user_tz":300,"elapsed":311,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"b0a8969e-0f00-4f16-dbb8-590e5b77795c"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" hero1 hero2 comic\n","0 ZAKKA BROTHER TODE E 1\n","1 ZAKKA DAMIAN, DR. DANIEL E 1\n","2 ZAKKA DAMIAN, MARGO E 1\n","3 ZAKKA IKARIS/IKE HARRIS [E E 1\n","4 ZAKKA KARKAS [DEVIANT] E 1\n","... ... ... ...\n","426553 BLAQUESMITH PSYLOCKE/ELISABETH B C2 31\n","426554 BLAQUESMITH PSYLOCKE/ELISABETH B X:PRIME\n","426555 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 52\n","426556 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 53\n","426557 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 54\n","\n","[426558 rows x 3 columns]"],"text/html":["\n","
\n","
\n","\n","
\n"," \n"," \n"," | \n"," hero1 | \n"," hero2 | \n"," comic | \n","
\n"," \n"," \n"," \n"," 0 | \n"," ZAKKA | \n"," BROTHER TODE | \n"," E 1 | \n","
\n"," \n"," 1 | \n"," ZAKKA | \n"," DAMIAN, DR. DANIEL | \n"," E 1 | \n","
\n"," \n"," 2 | \n"," ZAKKA | \n"," DAMIAN, MARGO | \n"," E 1 | \n","
\n"," \n"," 3 | \n"," ZAKKA | \n"," IKARIS/IKE HARRIS [E | \n"," E 1 | \n","
\n"," \n"," 4 | \n"," ZAKKA | \n"," KARKAS [DEVIANT] | \n"," E 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," 426553 | \n"," BLAQUESMITH | \n"," PSYLOCKE/ELISABETH B | \n"," C2 31 | \n","
\n"," \n"," 426554 | \n"," BLAQUESMITH | \n"," PSYLOCKE/ELISABETH B | \n"," X:PRIME | \n","
\n"," \n"," 426555 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 52 | \n","
\n"," \n"," 426556 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 53 | \n","
\n"," \n"," 426557 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 54 | \n","
\n"," \n","
\n","
426558 rows × 3 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"hero_hero_comic"}},"metadata":{},"execution_count":8}],"source":["# Create a dataframe, containing hero pairs and the comics with them\n","unknown_pairs=list(set(adding_pairs)-set(existing_pairs))\n","for pair in unknown_pairs:\n"," hero1=pair[0]\n"," hero2=pair[1]\n"," if len(hero_hero[(hero_hero['hero1']==pair[0]) & (hero_hero['hero2']==pair[1])])==1:\n"," count=hero_hero[(hero_hero['hero1']==pair[0]) & (hero_hero['hero2']==pair[1])]['counts'].iloc[0]\n"," for i in range(int(count)):\n"," hero_hero_comic.loc[len(hero_hero_comic)]=[hero1,hero2,'UNKNOWN']\n"," else:\n"," continue\n","\n","hero_hero_comic=hero_hero_comic.reset_index(drop=True)\n","hero_hero_comic"]},{"cell_type":"code","execution_count":9,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":424},"id":"uCmZdjgMr4az","executionInfo":{"status":"ok","timestamp":1709308287568,"user_tz":300,"elapsed":285,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"4e747d00-5111-437c-9386-929a973402e7"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" hero1 hero2 counts\n","0 3-D MAN/CHARLES CHAN AJAK/TECUMOTZIN [ETE 1\n","1 3-D MAN/CHARLES CHAN ANGEL/WARREN KENNETH 1\n","2 3-D MAN/CHARLES CHAN ANT-MAN II/SCOTT HAR 1\n","3 3-D MAN/CHARLES CHAN ANT-MAN/DR. HENRY J. 2\n","4 3-D MAN/CHARLES CHAN ARABIAN KNIGHT/ABDUL 1\n","... ... ... ...\n","142284 ZZZAX RODRIGUEZ, DEBRA 1\n","142285 ZZZAX SUMMERS, NATHAN CHRI 1\n","142286 ZZZAX TALBOT, GLENN 1\n","142287 ZZZAX TIGRA/GREER NELSON 1\n","142288 ZZZAX WONDER MAN/SIMON WIL 1\n","\n","[142289 rows x 3 columns]"],"text/html":["\n"," \n","
\n","\n","
\n"," \n"," \n"," | \n"," hero1 | \n"," hero2 | \n"," counts | \n","
\n"," \n"," \n"," \n"," 0 | \n"," 3-D MAN/CHARLES CHAN | \n"," AJAK/TECUMOTZIN [ETE | \n"," 1 | \n","
\n"," \n"," 1 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANGEL/WARREN KENNETH | \n"," 1 | \n","
\n"," \n"," 2 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANT-MAN II/SCOTT HAR | \n"," 1 | \n","
\n"," \n"," 3 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANT-MAN/DR. HENRY J. | \n"," 2 | \n","
\n"," \n"," 4 | \n"," 3-D MAN/CHARLES CHAN | \n"," ARABIAN KNIGHT/ABDUL | \n"," 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," 142284 | \n"," ZZZAX | \n"," RODRIGUEZ, DEBRA | \n"," 1 | \n","
\n"," \n"," 142285 | \n"," ZZZAX | \n"," SUMMERS, NATHAN CHRI | \n"," 1 | \n","
\n"," \n"," 142286 | \n"," ZZZAX | \n"," TALBOT, GLENN | \n"," 1 | \n","
\n"," \n"," 142287 | \n"," ZZZAX | \n"," TIGRA/GREER NELSON | \n"," 1 | \n","
\n"," \n"," 142288 | \n"," ZZZAX | \n"," WONDER MAN/SIMON WIL | \n"," 1 | \n","
\n"," \n","
\n","
142289 rows × 3 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"hero_hero"}},"metadata":{},"execution_count":9}],"source":["# Create weighted adjacent matrix/list for this network\n","hero_hero=hero_hero_comic.groupby(['hero1','hero2']).size().reset_index(name='counts')\n","hero_hero"]},{"cell_type":"code","execution_count":10,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":528},"id":"4NDlz9mpr4a0","executionInfo":{"status":"ok","timestamp":1709308289543,"user_tz":300,"elapsed":1977,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"6b3f7c37-41ba-4b8c-d881-498fa7a6addf"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" 3-D MAN/CHARLES CHAN AJAK/TECUMOTZIN [ETE \\\n","3-D MAN/CHARLES CHAN 102 1 \n","AJAK/TECUMOTZIN [ETE 1 175 \n","ANGEL/WARREN KENNETH 1 1 \n","ANT-MAN II/SCOTT HAR 1 1 \n","ANT-MAN/DR. HENRY J. 2 0 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 0 0 \n","\n"," ANGEL/WARREN KENNETH ANT-MAN II/SCOTT HAR \\\n","3-D MAN/CHARLES CHAN 1 1 \n","AJAK/TECUMOTZIN [ETE 1 1 \n","ANGEL/WARREN KENNETH 1083 3 \n","ANT-MAN II/SCOTT HAR 3 383 \n","ANT-MAN/DR. HENRY J. 25 14 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 0 1 \n","\n"," ANT-MAN/DR. HENRY J. ARABIAN KNIGHT/ABDUL \\\n","3-D MAN/CHARLES CHAN 2 1 \n","AJAK/TECUMOTZIN [ETE 0 1 \n","ANGEL/WARREN KENNETH 25 4 \n","ANT-MAN II/SCOTT HAR 14 1 \n","ANT-MAN/DR. HENRY J. 1063 0 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 2 0 \n","ZEAKLAR 0 0 \n","ZZZAX 1 0 \n","\n"," BANNER, BETTY ROSS T BEAST/HENRY &HANK& P \\\n","3-D MAN/CHARLES CHAN 2 1 \n","AJAK/TECUMOTZIN [ETE 0 1 \n","ANGEL/WARREN KENNETH 2 305 \n","ANT-MAN II/SCOTT HAR 1 7 \n","ANT-MAN/DR. HENRY J. 8 98 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 3 0 \n","\n"," BLACK BOLT/BLACKANTO BLACK PANTHER/T'CHAL ... \\\n","3-D MAN/CHARLES CHAN 1 1 ... \n","AJAK/TECUMOTZIN [ETE 1 1 ... \n","ANGEL/WARREN KENNETH 8 11 ... \n","ANT-MAN II/SCOTT HAR 9 8 ... \n","ANT-MAN/DR. HENRY J. 7 86 ... \n","... ... ... ... \n","YSSA 0 0 ... \n","ZAKKA 0 0 ... \n","ZCANN 0 1 ... \n","ZEAKLAR 0 0 ... \n","ZZZAX 0 0 ... \n","\n"," WOLFSBANE 2013 WOO, SONIA XEMU YELLOWJACKET II/RITA \\\n","3-D MAN/CHARLES CHAN 0 0 0 0 \n","AJAK/TECUMOTZIN [ETE 0 0 0 0 \n","ANGEL/WARREN KENNETH 0 0 0 0 \n","ANT-MAN II/SCOTT HAR 0 0 0 3 \n","ANT-MAN/DR. HENRY J. 0 0 0 2 \n","... ... ... ... ... \n","YSSA 0 0 0 0 \n","ZAKKA 0 0 0 0 \n","ZCANN 0 0 0 0 \n","ZEAKLAR 0 0 0 0 \n","ZZZAX 0 0 0 0 \n","\n"," YOUNG, KIM SUNG YSSA ZAKKA ZCANN ZEAKLAR ZZZAX \n","3-D MAN/CHARLES CHAN 0 0 0 0 0 0 \n","AJAK/TECUMOTZIN [ETE 0 0 0 0 0 0 \n","ANGEL/WARREN KENNETH 0 0 0 0 0 0 \n","ANT-MAN II/SCOTT HAR 0 0 0 0 0 1 \n","ANT-MAN/DR. HENRY J. 0 0 0 2 0 1 \n","... ... ... ... ... ... ... \n","YSSA 0 12 0 0 0 0 \n","ZAKKA 0 0 11 0 0 0 \n","ZCANN 0 0 0 72 0 0 \n","ZEAKLAR 0 0 0 0 2 0 \n","ZZZAX 0 0 0 0 0 26 \n","\n","[6267 rows x 6267 columns]"],"text/html":["\n"," \n","
\n","\n","
\n"," \n"," \n"," | \n"," 3-D MAN/CHARLES CHAN | \n"," AJAK/TECUMOTZIN [ETE | \n"," ANGEL/WARREN KENNETH | \n"," ANT-MAN II/SCOTT HAR | \n"," ANT-MAN/DR. HENRY J. | \n"," ARABIAN KNIGHT/ABDUL | \n"," BANNER, BETTY ROSS T | \n"," BEAST/HENRY &HANK& P | \n"," BLACK BOLT/BLACKANTO | \n"," BLACK PANTHER/T'CHAL | \n"," ... | \n"," WOLFSBANE 2013 | \n"," WOO, SONIA | \n"," XEMU | \n"," YELLOWJACKET II/RITA | \n"," YOUNG, KIM SUNG | \n"," YSSA | \n"," ZAKKA | \n"," ZCANN | \n"," ZEAKLAR | \n"," ZZZAX | \n","
\n"," \n"," \n"," \n"," 3-D MAN/CHARLES CHAN | \n"," 102 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," 2 | \n"," 1 | \n"," 2 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," AJAK/TECUMOTZIN [ETE | \n"," 1 | \n"," 175 | \n"," 1 | \n"," 1 | \n"," 0 | \n"," 1 | \n"," 0 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ANGEL/WARREN KENNETH | \n"," 1 | \n"," 1 | \n"," 1083 | \n"," 3 | \n"," 25 | \n"," 4 | \n"," 2 | \n"," 305 | \n"," 8 | \n"," 11 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ANT-MAN II/SCOTT HAR | \n"," 1 | \n"," 1 | \n"," 3 | \n"," 383 | \n"," 14 | \n"," 1 | \n"," 1 | \n"," 7 | \n"," 9 | \n"," 8 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 3 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n","
\n"," \n"," ANT-MAN/DR. HENRY J. | \n"," 2 | \n"," 0 | \n"," 25 | \n"," 14 | \n"," 1063 | \n"," 0 | \n"," 8 | \n"," 98 | \n"," 7 | \n"," 86 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," YSSA | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 12 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZAKKA | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 11 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZCANN | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 72 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZEAKLAR | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n","
\n"," \n"," ZZZAX | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n"," 1 | \n"," 0 | \n"," 3 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 26 | \n","
\n"," \n","
\n","
6267 rows × 6267 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"Adj"}},"metadata":{},"execution_count":10}],"source":["# Create Weighted Adjcent Matrix. weight to be the times the hero pair shows together; values on diagnal to be the degree of each node\n","G=nx.from_pandas_edgelist(hero_hero,'hero1','hero2',edge_attr='counts')\n","G=nx.Graph(G)\n","Adj=nx.adjacency_matrix(G,weight='counts').todense()\n","deg=[x[1] for x in list(G.degree)]\n","for i in range(len(Adj)):\n"," Adj[i,i]=deg[i]\n","hero=list(G.nodes)\n","Adj=pd.DataFrame(Adj,columns=hero,index=hero)\n","Adj"]},{"cell_type":"code","execution_count":11,"metadata":{"id":"Ww_M_4Isr4a0","executionInfo":{"status":"ok","timestamp":1709308303194,"user_tz":300,"elapsed":13654,"user":{"displayName":"清水幸","userId":"09251711040897455590"}}},"outputs":[],"source":["# save the tables\n","hero_hero_comic.to_csv('hero_hero_comic.cvs')\n","hero_hero.to_csv('adjacency_list.cvs')\n","Adj.to_csv('adjacency_matrix.cvs')"]}],"metadata":{"kernelspec":{"display_name":"Python 3.11.4 64-bit","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.4"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"9c3b746aacb193ef1cc3db259ac9b06b57bc8ebd00118a6d0bcea7cc554049a7"}},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
\ No newline at end of file
+{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EvTuwbs9r4aw","executionInfo":{"status":"ok","timestamp":1709307950772,"user_tz":300,"elapsed":18530,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"e4c04ebf-fb5a-4990-da77-a450598b3df7"},"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n","/content/drive/MyDrive/Colab_Notebooks/Marvel_network\n"]}],"source":["import numpy as np\n","import pandas as pd\n","import networkx as nx\n","import matplotlib.pyplot as plt\n","from tqdm import trange\n","from google.colab import drive\n","drive.mount('/content/drive')\n","%cd /content/drive/MyDrive/Colab_Notebooks/Marvel_network"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QHxuWhh8r4ay","executionInfo":{"status":"ok","timestamp":1709308038937,"user_tz":300,"elapsed":1658,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"ff562e1f-3640-49d7-bcf1-9f69c9f127ad"},"outputs":[{"output_type":"stream","name":"stdout","text":["96104\n","574467\n"]}],"source":["# Read datasets\n","elements=pd.read_csv('source_data/nodes.csv')\n","hero=elements[elements['type']=='hero']['node']\n","comic=elements[elements['type']=='comic']['node']\n","hero_comic=pd.read_csv('source_data/edges.csv')\n","print(len(hero_comic))\n","hero_hero=pd.read_csv('source_data/hero-network.csv')\n","print(len(hero_hero))"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"KFLbMoter4ay","executionInfo":{"status":"ok","timestamp":1709308042509,"user_tz":300,"elapsed":306,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"f7898146-fca2-4056-b846-1151f5d34583"},"outputs":[{"output_type":"stream","name":"stdout","text":["82593\n","424270\n"]}],"source":["# Create hero and comic lists\n","hero=list((set(hero_hero['hero1']).union(\n"," set(hero_hero['hero2']))).intersection(\n"," set(hero_comic['hero'])).intersection(\n"," set(hero)\n"," ))\n","\n","comic=list(set(hero_comic['comic']).intersection(set(comic)))\n","\n","# Delete edges containing unknown hero/comic\n","hero_comic=hero_comic[hero_comic['comic'].isin(comic)]\n","hero_comic=hero_comic[hero_comic['hero'].isin(hero)]\n","print(len(hero_comic))\n","\n","hero_hero=hero_hero[hero_hero['hero1'].isin(hero)]\n","hero_hero=hero_hero[hero_hero['hero2'].isin(hero)]\n","print(len(hero_hero))"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_BrGgTMMr4az","executionInfo":{"status":"ok","timestamp":1709308185730,"user_tz":300,"elapsed":140840,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"8b2f9eea-5144-48e7-b33c-f17e8525610d"},"outputs":[{"output_type":"stream","name":"stderr","text":["100%|██████████| 6282/6282 [02:20<00:00, 44.62it/s]\n"]}],"source":["# Determine in which comics the hero pairs meet\n","hero_hero_comic=pd.DataFrame(columns=['hero1','hero2','comic'])\n","for i in trange(len(hero)):\n"," hero1=hero[i]\n"," pair1=hero_comic[hero_comic['hero']==hero1]\n"," hero_comic=hero_comic[hero_comic['hero']!=hero1]\n"," pair2=hero_comic[hero_comic['comic'].isin(pair1['comic'])]\n"," pair2.columns=['hero2', 'comic']\n"," pair2.insert(0,'hero1',hero1,True)\n"," hero_hero_comic=pd.concat([hero_hero_comic,pair2])"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gBvjnLn0r4az","executionInfo":{"status":"ok","timestamp":1709308287123,"user_tz":300,"elapsed":101398,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"c6757189-dd0f-4f67-9e92-709dcd87be0b"},"outputs":[{"output_type":"stream","name":"stderr","text":["100%|██████████| 142289/142289 [00:25<00:00, 5543.05it/s]\n","100%|██████████| 183645/183645 [01:15<00:00, 2442.47it/s]\n"]}],"source":["def flatten_list(matrix):\n"," flat_list = []\n"," for row in matrix:\n"," flat_list += row\n"," return flat_list\n","\n","# List unique pairs\n","existing_pairs=hero_hero_comic[['hero1','hero2']].drop_duplicates()\n","existing_pairs=[[(existing_pairs.iloc[i]['hero1'],existing_pairs.iloc[i]['hero2']),\n"," (existing_pairs.iloc[i]['hero2'],existing_pairs.iloc[i]['hero1']) ]\n"," for i in trange(len(existing_pairs))]\n","existing_pairs=flatten_list(existing_pairs)\n","\n","hero_hero=hero_hero.groupby(['hero1','hero2']).size().reset_index(name='counts')\n","adding_pairs=hero_hero.drop_duplicates()\n","adding_pairs=[(adding_pairs.iloc[i]['hero1'],adding_pairs.iloc[i]['hero2'])\n"," for i in trange(len(adding_pairs))\n"," if adding_pairs.iloc[i]['hero1']!=adding_pairs.iloc[i]['hero2']]\n"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":424},"id":"A07g1IEzr4az","executionInfo":{"status":"ok","timestamp":1709308287288,"user_tz":300,"elapsed":311,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"b0a8969e-0f00-4f16-dbb8-590e5b77795c"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" hero1 hero2 comic\n","0 ZAKKA BROTHER TODE E 1\n","1 ZAKKA DAMIAN, DR. DANIEL E 1\n","2 ZAKKA DAMIAN, MARGO E 1\n","3 ZAKKA IKARIS/IKE HARRIS [E E 1\n","4 ZAKKA KARKAS [DEVIANT] E 1\n","... ... ... ...\n","426553 BLAQUESMITH PSYLOCKE/ELISABETH B C2 31\n","426554 BLAQUESMITH PSYLOCKE/ELISABETH B X:PRIME\n","426555 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 52\n","426556 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 53\n","426557 PALADIN/PAUL DENNIS FROST, ADRIENNE GENX 54\n","\n","[426558 rows x 3 columns]"],"text/html":["\n"," \n","
\n","\n","
\n"," \n"," \n"," | \n"," hero1 | \n"," hero2 | \n"," comic | \n","
\n"," \n"," \n"," \n"," 0 | \n"," ZAKKA | \n"," BROTHER TODE | \n"," E 1 | \n","
\n"," \n"," 1 | \n"," ZAKKA | \n"," DAMIAN, DR. DANIEL | \n"," E 1 | \n","
\n"," \n"," 2 | \n"," ZAKKA | \n"," DAMIAN, MARGO | \n"," E 1 | \n","
\n"," \n"," 3 | \n"," ZAKKA | \n"," IKARIS/IKE HARRIS [E | \n"," E 1 | \n","
\n"," \n"," 4 | \n"," ZAKKA | \n"," KARKAS [DEVIANT] | \n"," E 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," 426553 | \n"," BLAQUESMITH | \n"," PSYLOCKE/ELISABETH B | \n"," C2 31 | \n","
\n"," \n"," 426554 | \n"," BLAQUESMITH | \n"," PSYLOCKE/ELISABETH B | \n"," X:PRIME | \n","
\n"," \n"," 426555 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 52 | \n","
\n"," \n"," 426556 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 53 | \n","
\n"," \n"," 426557 | \n"," PALADIN/PAUL DENNIS | \n"," FROST, ADRIENNE | \n"," GENX 54 | \n","
\n"," \n","
\n","
426558 rows × 3 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"hero_hero_comic"}},"metadata":{},"execution_count":8}],"source":["# Create a dataframe, containing hero pairs and the comics with them\n","unknown_pairs=list(set(adding_pairs)-set(existing_pairs))\n","for pair in unknown_pairs:\n"," hero1=pair[0]\n"," hero2=pair[1]\n"," if len(hero_hero[(hero_hero['hero1']==pair[0]) & (hero_hero['hero2']==pair[1])])==1:\n"," count=hero_hero[(hero_hero['hero1']==pair[0]) & (hero_hero['hero2']==pair[1])]['counts'].iloc[0]\n"," for i in range(int(count)):\n"," hero_hero_comic.loc[len(hero_hero_comic)]=[hero1,hero2,'UNKNOWN']\n"," else:\n"," continue\n","\n","hero_hero_comic=hero_hero_comic.reset_index(drop=True)\n","hero_hero_comic"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":424},"id":"uCmZdjgMr4az","executionInfo":{"status":"ok","timestamp":1709308287568,"user_tz":300,"elapsed":285,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"4e747d00-5111-437c-9386-929a973402e7"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" hero1 hero2 counts\n","0 3-D MAN/CHARLES CHAN AJAK/TECUMOTZIN [ETE 1\n","1 3-D MAN/CHARLES CHAN ANGEL/WARREN KENNETH 1\n","2 3-D MAN/CHARLES CHAN ANT-MAN II/SCOTT HAR 1\n","3 3-D MAN/CHARLES CHAN ANT-MAN/DR. HENRY J. 2\n","4 3-D MAN/CHARLES CHAN ARABIAN KNIGHT/ABDUL 1\n","... ... ... ...\n","142284 ZZZAX RODRIGUEZ, DEBRA 1\n","142285 ZZZAX SUMMERS, NATHAN CHRI 1\n","142286 ZZZAX TALBOT, GLENN 1\n","142287 ZZZAX TIGRA/GREER NELSON 1\n","142288 ZZZAX WONDER MAN/SIMON WIL 1\n","\n","[142289 rows x 3 columns]"],"text/html":["\n"," \n","
\n","\n","
\n"," \n"," \n"," | \n"," hero1 | \n"," hero2 | \n"," counts | \n","
\n"," \n"," \n"," \n"," 0 | \n"," 3-D MAN/CHARLES CHAN | \n"," AJAK/TECUMOTZIN [ETE | \n"," 1 | \n","
\n"," \n"," 1 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANGEL/WARREN KENNETH | \n"," 1 | \n","
\n"," \n"," 2 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANT-MAN II/SCOTT HAR | \n"," 1 | \n","
\n"," \n"," 3 | \n"," 3-D MAN/CHARLES CHAN | \n"," ANT-MAN/DR. HENRY J. | \n"," 2 | \n","
\n"," \n"," 4 | \n"," 3-D MAN/CHARLES CHAN | \n"," ARABIAN KNIGHT/ABDUL | \n"," 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," 142284 | \n"," ZZZAX | \n"," RODRIGUEZ, DEBRA | \n"," 1 | \n","
\n"," \n"," 142285 | \n"," ZZZAX | \n"," SUMMERS, NATHAN CHRI | \n"," 1 | \n","
\n"," \n"," 142286 | \n"," ZZZAX | \n"," TALBOT, GLENN | \n"," 1 | \n","
\n"," \n"," 142287 | \n"," ZZZAX | \n"," TIGRA/GREER NELSON | \n"," 1 | \n","
\n"," \n"," 142288 | \n"," ZZZAX | \n"," WONDER MAN/SIMON WIL | \n"," 1 | \n","
\n"," \n","
\n","
142289 rows × 3 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"hero_hero"}},"metadata":{},"execution_count":9}],"source":["# Create weighted adjacent matrix/list for this network\n","hero_hero=hero_hero_comic.groupby(['hero1','hero2']).size().reset_index(name='counts')\n","hero_hero"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":528},"id":"4NDlz9mpr4a0","executionInfo":{"status":"ok","timestamp":1709308289543,"user_tz":300,"elapsed":1977,"user":{"displayName":"清水幸","userId":"09251711040897455590"}},"outputId":"6b3f7c37-41ba-4b8c-d881-498fa7a6addf"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" 3-D MAN/CHARLES CHAN AJAK/TECUMOTZIN [ETE \\\n","3-D MAN/CHARLES CHAN 102 1 \n","AJAK/TECUMOTZIN [ETE 1 175 \n","ANGEL/WARREN KENNETH 1 1 \n","ANT-MAN II/SCOTT HAR 1 1 \n","ANT-MAN/DR. HENRY J. 2 0 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 0 0 \n","\n"," ANGEL/WARREN KENNETH ANT-MAN II/SCOTT HAR \\\n","3-D MAN/CHARLES CHAN 1 1 \n","AJAK/TECUMOTZIN [ETE 1 1 \n","ANGEL/WARREN KENNETH 1083 3 \n","ANT-MAN II/SCOTT HAR 3 383 \n","ANT-MAN/DR. HENRY J. 25 14 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 0 1 \n","\n"," ANT-MAN/DR. HENRY J. ARABIAN KNIGHT/ABDUL \\\n","3-D MAN/CHARLES CHAN 2 1 \n","AJAK/TECUMOTZIN [ETE 0 1 \n","ANGEL/WARREN KENNETH 25 4 \n","ANT-MAN II/SCOTT HAR 14 1 \n","ANT-MAN/DR. HENRY J. 1063 0 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 2 0 \n","ZEAKLAR 0 0 \n","ZZZAX 1 0 \n","\n"," BANNER, BETTY ROSS T BEAST/HENRY &HANK& P \\\n","3-D MAN/CHARLES CHAN 2 1 \n","AJAK/TECUMOTZIN [ETE 0 1 \n","ANGEL/WARREN KENNETH 2 305 \n","ANT-MAN II/SCOTT HAR 1 7 \n","ANT-MAN/DR. HENRY J. 8 98 \n","... ... ... \n","YSSA 0 0 \n","ZAKKA 0 0 \n","ZCANN 0 0 \n","ZEAKLAR 0 0 \n","ZZZAX 3 0 \n","\n"," BLACK BOLT/BLACKANTO BLACK PANTHER/T'CHAL ... \\\n","3-D MAN/CHARLES CHAN 1 1 ... \n","AJAK/TECUMOTZIN [ETE 1 1 ... \n","ANGEL/WARREN KENNETH 8 11 ... \n","ANT-MAN II/SCOTT HAR 9 8 ... \n","ANT-MAN/DR. HENRY J. 7 86 ... \n","... ... ... ... \n","YSSA 0 0 ... \n","ZAKKA 0 0 ... \n","ZCANN 0 1 ... \n","ZEAKLAR 0 0 ... \n","ZZZAX 0 0 ... \n","\n"," WOLFSBANE 2013 WOO, SONIA XEMU YELLOWJACKET II/RITA \\\n","3-D MAN/CHARLES CHAN 0 0 0 0 \n","AJAK/TECUMOTZIN [ETE 0 0 0 0 \n","ANGEL/WARREN KENNETH 0 0 0 0 \n","ANT-MAN II/SCOTT HAR 0 0 0 3 \n","ANT-MAN/DR. HENRY J. 0 0 0 2 \n","... ... ... ... ... \n","YSSA 0 0 0 0 \n","ZAKKA 0 0 0 0 \n","ZCANN 0 0 0 0 \n","ZEAKLAR 0 0 0 0 \n","ZZZAX 0 0 0 0 \n","\n"," YOUNG, KIM SUNG YSSA ZAKKA ZCANN ZEAKLAR ZZZAX \n","3-D MAN/CHARLES CHAN 0 0 0 0 0 0 \n","AJAK/TECUMOTZIN [ETE 0 0 0 0 0 0 \n","ANGEL/WARREN KENNETH 0 0 0 0 0 0 \n","ANT-MAN II/SCOTT HAR 0 0 0 0 0 1 \n","ANT-MAN/DR. HENRY J. 0 0 0 2 0 1 \n","... ... ... ... ... ... ... \n","YSSA 0 12 0 0 0 0 \n","ZAKKA 0 0 11 0 0 0 \n","ZCANN 0 0 0 72 0 0 \n","ZEAKLAR 0 0 0 0 2 0 \n","ZZZAX 0 0 0 0 0 26 \n","\n","[6267 rows x 6267 columns]"],"text/html":["\n"," \n","
\n","\n","
\n"," \n"," \n"," | \n"," 3-D MAN/CHARLES CHAN | \n"," AJAK/TECUMOTZIN [ETE | \n"," ANGEL/WARREN KENNETH | \n"," ANT-MAN II/SCOTT HAR | \n"," ANT-MAN/DR. HENRY J. | \n"," ARABIAN KNIGHT/ABDUL | \n"," BANNER, BETTY ROSS T | \n"," BEAST/HENRY &HANK& P | \n"," BLACK BOLT/BLACKANTO | \n"," BLACK PANTHER/T'CHAL | \n"," ... | \n"," WOLFSBANE 2013 | \n"," WOO, SONIA | \n"," XEMU | \n"," YELLOWJACKET II/RITA | \n"," YOUNG, KIM SUNG | \n"," YSSA | \n"," ZAKKA | \n"," ZCANN | \n"," ZEAKLAR | \n"," ZZZAX | \n","
\n"," \n"," \n"," \n"," 3-D MAN/CHARLES CHAN | \n"," 102 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," 2 | \n"," 1 | \n"," 2 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," AJAK/TECUMOTZIN [ETE | \n"," 1 | \n"," 175 | \n"," 1 | \n"," 1 | \n"," 0 | \n"," 1 | \n"," 0 | \n"," 1 | \n"," 1 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ANGEL/WARREN KENNETH | \n"," 1 | \n"," 1 | \n"," 1083 | \n"," 3 | \n"," 25 | \n"," 4 | \n"," 2 | \n"," 305 | \n"," 8 | \n"," 11 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ANT-MAN II/SCOTT HAR | \n"," 1 | \n"," 1 | \n"," 3 | \n"," 383 | \n"," 14 | \n"," 1 | \n"," 1 | \n"," 7 | \n"," 9 | \n"," 8 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 3 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n","
\n"," \n"," ANT-MAN/DR. HENRY J. | \n"," 2 | \n"," 0 | \n"," 25 | \n"," 14 | \n"," 1063 | \n"," 0 | \n"," 8 | \n"," 98 | \n"," 7 | \n"," 86 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 1 | \n","
\n"," \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n"," ... | \n","
\n"," \n"," YSSA | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 12 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZAKKA | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 11 | \n"," 0 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZCANN | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 72 | \n"," 0 | \n"," 0 | \n","
\n"," \n"," ZEAKLAR | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 2 | \n"," 0 | \n","
\n"," \n"," ZZZAX | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 1 | \n"," 1 | \n"," 0 | \n"," 3 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," ... | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 0 | \n"," 26 | \n","
\n"," \n","
\n","
6267 rows × 6267 columns
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"Adj"}},"metadata":{},"execution_count":10}],"source":["# Create Weighted Adjcent Matrix. weight to be the times the hero pair shows together; values on diagnal to be the degree of each node\n","G=nx.from_pandas_edgelist(hero_hero,'hero1','hero2',edge_attr='counts')\n","G=nx.Graph(G)\n","Adj=nx.adjacency_matrix(G,weight='counts').todense()\n","deg=[x[1] for x in list(G.degree)]\n","for i in range(len(Adj)):\n"," Adj[i,i]=deg[i]\n","hero=list(G.nodes)\n","Adj=pd.DataFrame(Adj,columns=hero,index=hero)\n","Adj"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Ww_M_4Isr4a0"},"outputs":[],"source":["# save the tables\n","hero_hero_comic.to_csv('hero_hero_comic.csv',index=False)\n","hero_hero.to_csv('adjacency_list.csv',index=False)\n","Adj.to_csv('adjacency_matrix.csv')"]}],"metadata":{"kernelspec":{"display_name":"Python 3.11.4 64-bit","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.4"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"9c3b746aacb193ef1cc3db259ac9b06b57bc8ebd00118a6d0bcea7cc554049a7"}},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
\ No newline at end of file