1
0

优化金字塔选股结果格式

This commit is contained in:
2025-01-13 14:16:47 +08:00
parent 05e21635ef
commit 64ea792444
3 changed files with 1002 additions and 40013 deletions

1
.gitignore vendored
View File

@@ -117,3 +117,4 @@ cython_debug/
# Custom
temp/
temp/**/*
.idea/**/csv-editor.xml

View File

@@ -4,7 +4,11 @@
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-01-13T01:30:08.643756Z",
"start_time": "2025-01-13T01:30:06.177472Z"
}
},
"source": [
"import pandas as pd\n",
@@ -13,10 +17,15 @@
"ts_pro = ts.pro_api(token=\"64ebff4fa679167600b905ee45dd88e76f3963c0ff39157f3f085f0e\")"
],
"outputs": [],
"execution_count": null
"execution_count": 1
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:30:08.652416Z",
"start_time": "2025-01-13T01:30:08.646084Z"
}
},
"cell_type": "code",
"source": [
"def get_balance_sheet_df(start_year, end_year):\n",
@@ -59,10 +68,15 @@
],
"id": "14a28ff4952f0df8",
"outputs": [],
"execution_count": null
"execution_count": 2
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:30:08.656800Z",
"start_time": "2025-01-13T01:30:08.653794Z"
}
},
"cell_type": "code",
"source": [
"start_year = 2014\n",
@@ -70,10 +84,15 @@
],
"id": "dc68cde196159626",
"outputs": [],
"execution_count": null
"execution_count": 3
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:39:39.349170Z",
"start_time": "2025-01-13T01:30:08.660347Z"
}
},
"cell_type": "code",
"source": [
"# 财务负债表\n",
@@ -81,33 +100,168 @@
"balance_sheet_df.to_csv(\"../temp/balance_sheet.csv\", index=False)"
],
"id": "33cd797a12ad567e",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull balance sheet: 2014\n",
"Pull balance sheet: 2015\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:8: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull balance sheet: 2016\n",
"Pull balance sheet: 2017\n",
"Pull balance sheet: 2018\n",
"Pull balance sheet: 2019\n",
"Pull balance sheet: 2020\n",
"Pull balance sheet: 2021\n",
"Pull balance sheet: 2022\n",
"Pull balance sheet: 2023\n",
"Pull balance sheet: 2024\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:8: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
}
],
"execution_count": 4
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:43:28.007135Z",
"start_time": "2025-01-13T01:39:39.363037Z"
}
},
"cell_type": "code",
"source": [
"income_df = clean_df(get_income_df(start_year, end_year))\n",
"income_df.to_csv(\"../temp/income.csv\", index=False)"
],
"id": "17306c1524f5e173",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull income: 2014\n",
"Pull income: 2015\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:19: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull income: 2016\n",
"Pull income: 2017\n",
"Pull income: 2018\n",
"Pull income: 2019\n",
"Pull income: 2020\n",
"Pull income: 2021\n",
"Pull income: 2022\n",
"Pull income: 2023\n",
"Pull income: 2024\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:19: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
}
],
"execution_count": 5
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:46:46.375157Z",
"start_time": "2025-01-13T01:43:28.011213Z"
}
},
"cell_type": "code",
"source": [
"cash_flow_df = clean_df(get_cash_flow_df(start_year, end_year))\n",
"cash_flow_df.to_csv(\"../temp/cash_flow.csv\", index=False)"
],
"id": "334dbe20f2047a1e",
"outputs": [],
"execution_count": null
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull cash flow: 2014\n",
"Pull cash flow: 2015\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:30: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pull cash flow: 2016\n",
"Pull cash flow: 2017\n",
"Pull cash flow: 2018\n",
"Pull cash flow: 2019\n",
"Pull cash flow: 2020\n",
"Pull cash flow: 2021\n",
"Pull cash flow: 2022\n",
"Pull cash flow: 2023\n",
"Pull cash flow: 2024\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/7h/w0cmp4zj6mn9br_6nyj310m40000gn/T/ipykernel_50121/709533518.py:30: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" result = pd.concat([result, temp], ignore_index=True)\n"
]
}
],
"execution_count": 6
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-13T01:46:57.717599Z",
"start_time": "2025-01-13T01:46:46.377806Z"
}
},
"cell_type": "code",
"source": [
"finance_df = pd.merge(balance_sheet_df, income_df, on=[\"ts_code\", \"end_date\"])\n",
@@ -116,13 +270,13 @@
],
"id": "f8bea62f377b5e2",
"outputs": [],
"execution_count": null
"execution_count": 7
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-12T12:04:00.424439Z",
"start_time": "2025-01-12T12:04:00.364557Z"
"end_time": "2025-01-13T01:46:57.814028Z",
"start_time": "2025-01-13T01:46:57.728111Z"
}
},
"cell_type": "code",
@@ -512,12 +666,12 @@
"</div>"
]
},
"execution_count": 29,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 29
"execution_count": 8
}
],
"metadata": {

File diff suppressed because it is too large Load Diff