{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Based on [this notebook](https://www.kaggle.com/code/yasufuminakama/ai4code-most-common-kagglers).\n\nGet the notebook citation counts for notebooks (i.e., count the times any of an author's notebooks got linked in other notebooks).","metadata":{}},{"cell_type":"code","source":"import os\nimport re\nimport json\nimport numpy as np\nimport pandas as pd\nfrom joblib import Parallel, delayed\nfrom collections import Counter","metadata":{"execution":{"iopub.status.busy":"2022-07-02T14:31:37.699012Z","iopub.execute_input":"2022-07-02T14:31:37.699370Z","iopub.status.idle":"2022-07-02T14:31:37.810869Z","shell.execute_reply.started":"2022-07-02T14:31:37.699279Z","shell.execute_reply":"2022-07-02T14:31:37.810138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_user(file):\n    json_open = open(f'../input/AI4Code/train/{file}', 'r')\n    json_load = json.load(json_open)\n    json_load = '\\n'.join(json_load['source'].values())\n    res = re.findall(r'www.kaggle.com/+([a-zA-Z0-9_]+)/', json_load)\n    res = set(res)\n    res = [r for r in res if r not in ['c', 'kernels', 'learn']]\n    return res\n\nfiles = os.listdir('../input/AI4Code/train')\nresult = Parallel(n_jobs=4, verbose=1)(delayed(extract_user)(file) for file in files)\nresult = sum(result, [])\ncount = Counter(result)","metadata":{"execution":{"iopub.status.busy":"2022-07-02T15:16:42.362843Z","iopub.execute_input":"2022-07-02T15:16:42.363128Z","iopub.status.idle":"2022-07-02T15:17:37.322303Z","shell.execute_reply.started":"2022-07-02T15:16:42.363097Z","shell.execute_reply":"2022-07-02T15:17:37.321663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"json_open = open(f'../input/AI4Code/train/{files[2]}', 'r')\njson_load = json.load(json_open)","metadata":{"execution":{"iopub.status.busy":"2022-07-02T15:02:06.387502Z","iopub.execute_input":"2022-07-02T15:02:06.387898Z","iopub.status.idle":"2022-07-02T15:02:06.398063Z","shell.execute_reply.started":"2022-07-02T15:02:06.387853Z","shell.execute_reply":"2022-07-02T15:02:06.397426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({\"username\": count.keys(), \"count\": count.values()}).sort_values(\"count\", ascending=False)\ndf[\"rank\"] = df[\"count\"].rank(ascending=False)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-02T15:17:37.323746Z","iopub.execute_input":"2022-07-02T15:17:37.324637Z","iopub.status.idle":"2022-07-02T15:17:37.343845Z","shell.execute_reply.started":"2022-07-02T15:17:37.324586Z","shell.execute_reply":"2022-07-02T15:17:37.343274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df.username == \"ceshine\"]","metadata":{"execution":{"iopub.status.busy":"2022-07-02T15:17:37.344868Z","iopub.execute_input":"2022-07-02T15:17:37.345433Z","iopub.status.idle":"2022-07-02T15:17:37.355969Z","shell.execute_reply.started":"2022-07-02T15:17:37.345379Z","shell.execute_reply":"2022-07-02T15:17:37.355275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# TOP30\nfor i, c in enumerate(count.most_common(30)):\n    print(i+1, c)","metadata":{"execution":{"iopub.status.busy":"2022-07-02T15:18:45.279348Z","iopub.execute_input":"2022-07-02T15:18:45.279660Z","iopub.status.idle":"2022-07-02T15:18:45.292386Z","shell.execute_reply.started":"2022-07-02T15:18:45.279629Z","shell.execute_reply":"2022-07-02T15:18:45.290301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- Glad to know I'm 23rd :)","metadata":{}}]}