{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84493,"databundleVersionId":11037875,"sourceType":"competition"},{"sourceId":10723702,"sourceType":"datasetVersion","datasetId":6647566}],"dockerImageVersionId":30886,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom glob import glob\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:06:48.520424Z","iopub.execute_input":"2025-02-11T15:06:48.520871Z","iopub.status.idle":"2025-02-11T15:06:48.950588Z","shell.execute_reply.started":"2025-02-11T15:06:48.520826Z","shell.execute_reply":"2025-02-11T15:06:48.949242Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"csv_list = glob(\"/kaggle/input/jane-street-public-leaderboard/*.csv\")\n\ndf_list = []\n\nfor x in csv_list:\n    _df = pd.read_csv(x)\n    _df['Timestamp'] = pd.to_datetime(\n        x.split(\"/\")[-1].split(\".\")[-2][-19:], \n        format=\"%Y-%m-%dT%H_%M_%S\"\n        )\n    df_list.append(_df)\n\ndf_all = pd.concat(df_list)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:06:48.952867Z","iopub.execute_input":"2025-02-11T15:06:48.953441Z","iopub.status.idle":"2025-02-11T15:06:48.993813Z","shell.execute_reply.started":"2025-02-11T15:06:48.953408Z","shell.execute_reply":"2025-02-11T15:06:48.992946Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_all.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:06:48.995105Z","iopub.execute_input":"2025-02-11T15:06:48.995498Z","iopub.status.idle":"2025-02-11T15:06:49.013714Z","shell.execute_reply.started":"2025-02-11T15:06:48.995430Z","shell.execute_reply":"2025-02-11T15:06:49.012408Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_all = df_all.sort_values(by=['TeamName', 'Timestamp'])\ndf_all['RankChange'] = df_all.groupby(['TeamName'])['Rank'].diff()\n\nfig, ax = plt.subplots()\nax.hist(df_all['RankChange'].dropna().values, bins=100)\nax.set_title(\"Jane Street Competition Rank Change\")\nax.set_xlabel(\"Rank Change\")\nax.set_ylabel(\"Counts\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:06:49.014971Z","iopub.execute_input":"2025-02-11T15:06:49.015328Z","iopub.status.idle":"2025-02-11T15:06:49.360796Z","shell.execute_reply.started":"2025-02-11T15:06:49.015273Z","shell.execute_reply":"2025-02-11T15:06:49.359591Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%matplotlib inline \n\ndf_all = df_all.sort_values(by=['TeamName', 'Timestamp'])\n\ntimestamps = df_all['Timestamp'].unique()\n\nfirst_ts, second_ts = timestamps[-2], timestamps[-1]\ndf_first = df_all[df_all['Timestamp'] == first_ts][['TeamName', 'Rank']]\ndf_second = df_all[df_all['Timestamp'] == second_ts][['TeamName', 'Rank']]\n\ndf_first = df_first.rename(columns={'Rank': 'first_rank'})\ndf_second = df_second.rename(columns={'Rank': 'second_rank'})\n\ndf_merge = pd.merge(df_first, df_second, on='TeamName', how='inner')\n\nplt.figure(figsize=(8, 6))\nplt.scatter(df_merge['first_rank'], df_merge['second_rank'], alpha=0.7)\nplt.xlabel(f\"Rank at {first_ts.strftime('%Y-%m-%d %H:%M:%S')}\")\nplt.ylabel(f\"Rank at {second_ts.strftime('%Y-%m-%d %H:%M:%S')}\")\nplt.title(\"Scatter Plot: Rank at First vs Second Timestamp\")\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:06:49.361760Z","iopub.execute_input":"2025-02-11T15:06:49.362044Z","iopub.status.idle":"2025-02-11T15:06:49.637237Z","shell.execute_reply.started":"2025-02-11T15:06:49.362018Z","shell.execute_reply":"2025-02-11T15:06:49.636094Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_rank = df_merge.sort_values('second_rank').reset_index(drop=True)\ndf_rank = df_rank[df_rank['second_rank']<=100]\ndf_rank['rank_diff'] = -(df_rank['second_rank'] - df_rank['first_rank'])\n\nplt.rcParams['font.sans-serif'] = ['Microsoft YaHei']\nplt.rcParams['axes.unicode_minus'] = False\n\nplt.figure(figsize=(10, 22))  # 根据用户数调整高度\nplt.barh(df_rank['TeamName'], df_rank['rank_diff'], color='skyblue')\nplt.xlabel('Rank Difference (Second - First)')\nplt.ylabel('Team Name')\nplt.title('Rank Change between Two Timestamps')\nplt.grid( linestyle='--', alpha=0.7)\nplt.gca().invert_yaxis()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-11T15:13:25.723887Z","iopub.execute_input":"2025-02-11T15:13:25.724337Z","iopub.status.idle":"2025-02-11T15:13:26.842312Z","shell.execute_reply.started":"2025-02-11T15:13:25.724275Z","shell.execute_reply":"2025-02-11T15:13:26.841035Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}