{ "cells": [ { "cell_type": "code", "execution_count": 54, "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2023-06-03T01:36:32.345509400Z", "start_time": "2023-06-03T01:36:32.332130700Z" } }, "outputs": [], "source": [ "from typing import Final\n", "\n", "import numpy as np\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 1, "outputs": [ { "data": { "text/plain": " Company 1 Connection Weight Company 2\n0 21 83 58\n1 37 88 86\n2 40 6 83\n3 60 35 2\n4 11 22 10\n.. ... ... ...\n695 62 37 11\n696 10 24 27\n697 97 40 55\n698 14 87 66\n699 50 55 82\n\n[693 rows x 3 columns]", "text/html": "
\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 \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 \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
Company 1Connection WeightCompany 2
0218358
1378886
240683
360352
4112210
............
695623711
696102427
697974055
698148766
699505582
\n

693 rows × 3 columns

\n
" }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from typing import Final\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "number_of_entries = 100\n", "number_of_contacts = 10\n", "ids: Final = [_ for _ in range(number_of_entries)]\n", "companies = pd.DataFrame(columns=[], index=pd.Index(ids, name=\"company_id\"))\n", "companies\n", "\n", "\n", "id1 = (\n", " pd.Series(ids * number_of_contacts, name=\"Company 1\")\n", " .sample(frac=0.7, random_state=42)\n", " .reset_index(drop=True)\n", ")\n", "id2 = (\n", " pd.Series(ids * number_of_contacts, name=\"Company 2\")\n", " .sample(frac=0.7, random_state=43)\n", " .reset_index(drop=True)\n", ")\n", "connections = (\n", " pd.DataFrame(\n", " [\n", " id1,\n", " pd.Series(\n", " np.random.randint(0, 100, size=(max(len(id1), len(id2)))),\n", " name=\"Connection Weight\",\n", " ),\n", " id2,\n", " ]\n", " )\n", " .T.dropna()\n", " .astype(int)\n", ")\n", "connections = connections.loc[(connections[\"Company 1\"] != connections[\"Company 2\"])]\n", "connections" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-06-03T10:15:42.647508100Z", "start_time": "2023-06-03T10:15:40.656713900Z" } } }, { "cell_type": "code", "execution_count": 69, "outputs": [ { "data": { "text/plain": " Company 1 Connection Weight Company 2\n0 21 36 58\n1 37 59 86\n2 40 26 83\n3 60 21 2\n4 11 2 10\n.. ... ... ...\n695 62 45 11\n696 10 64 27\n697 97 24 55\n698 14 51 66\n699 50 93 82\n\n[693 rows x 3 columns]", "text/html": "
\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 \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 \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
Company 1Connection WeightCompany 2
0213658
1375986
2402683
360212
411210
............
695624511
696106427
697972455
698145166
699509382
\n

693 rows × 3 columns

\n
" }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id1 = (\n", " pd.Series(ids * number_of_contacts, name=\"Company 1\")\n", " .sample(frac=0.7, random_state=42)\n", " .reset_index(drop=True)\n", ")\n", "id2 = (\n", " pd.Series(ids * number_of_contacts, name=\"Company 2\")\n", " .sample(frac=0.7, random_state=43)\n", " .reset_index(drop=True)\n", ")\n", "connections = (\n", " pd.DataFrame(\n", " [\n", " id1,\n", " pd.Series(\n", " np.random.randint(0, 100, size=(max(len(id1), len(id2)))),\n", " name=\"Connection Weight\",\n", " ),\n", " id2,\n", " ]\n", " )\n", " .T.dropna()\n", " .astype(int)\n", ")\n", "connections = connections.loc[(connections[\"Company 1\"] != connections[\"Company 2\"])]\n", "connections" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-06-03T01:40:08.441882700Z", "start_time": "2023-06-03T01:40:08.406876900Z" } } }, { "cell_type": "code", "execution_count": 73, "outputs": [ { "data": { "text/plain": " Company 2\nCompany 1 \n0 6\n1 6\n2 5\n3 9\n4 7\n... ...\n95 7\n96 8\n97 7\n98 6\n99 8\n\n[100 rows x 1 columns]", "text/html": "
\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 \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 \n \n \n \n \n
Company 2
Company 1
06
16
25
39
47
......
957
968
977
986
998
\n

100 rows × 1 columns

\n
" }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "connections[[\"Company 1\", \"Company 2\"]].groupby(\"Company 1\").count()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-06-03T01:44:23.433333600Z", "start_time": "2023-06-03T01:44:23.424841700Z" } } }, { "cell_type": "code", "execution_count": 72, "outputs": [ { "data": { "text/plain": " Analysis-d0 Analysis-d1\ncompany_id \n0 1 6\n1 1 6\n2 1 5\n3 1 9\n4 1 7\n... ... ...\n95 1 7\n96 1 8\n97 1 7\n98 1 6\n99 1 8\n\n[100 rows x 2 columns]", "text/html": "
\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 \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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Analysis-d0Analysis-d1
company_id
016
116
215
319
417
.........
9517
9618
9717
9816
9918
\n

100 rows × 2 columns

\n
" }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "companies[\"Analysis-d0\"] = 1\n", "companies[\"Analysis-d1\"] = connections[[\"Company 1\", \"Company 2\"]].groupby(\"Company 1\").count()\n", "connection_sum = connections.join(connections.set_index(\"Company 2\"), on=)\n", "companies[\"Analysis-d1\"] = connections[[\"Company 1\", \"Company 2\"]].groupby(\"Company 1\").count()\n", "# for tiers in range(5):\n", "companies" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-06-03T01:43:25.341850700Z", "start_time": "2023-06-03T01:43:25.318015500Z" } } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "companies" ], "metadata": { "collapsed": false, "ExecuteTime": { "start_time": "2023-06-03T01:36:32.382091200Z" } } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [], "metadata": { "collapsed": false, "ExecuteTime": { "start_time": "2023-06-03T01:36:32.385093700Z" } } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }