@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1 ,
"execution_count": 3 ,
"id": "139fd1cb-aedf-4186-8408-4d630ba69599",
"metadata": {},
"outputs": [],
@ -639,7 +639,7 @@
},
{
"cell_type": "code",
"execution_count": 6 7,
"execution_count": 70 ,
"id": "4cd4cd6e-f34e-43a8-98de-c468a54d8081",
"metadata": {},
"outputs": [],
@ -656,7 +656,10 @@
"\treport_period = report_period_list;\n",
"\t\n",
"\tquery_table = table(report_period, m_nDate);\n",
"\tquery_table_exp = select * from cj(query_table, select code from source_table where partition(code, code_partition_id) group by code map);\n",
"\tquery_table_exp = select * from cj(\n",
" query_table, \n",
" select code from source_table where partition(code, code_partition_id\n",
" ) group by code map);\n",
"\t\n",
"\tcol_list = sqlCol(['code', 'report_period', 'appear_at_date', col_name]);\n",
" from_tbl = <ej(source_table, query_table_exp, `code`report_period)>;\n",
@ -672,7 +675,7 @@
},
{
"cell_type": "code",
"execution_count": 69 ,
"execution_count": 71 ,
"id": "943b760a-ab39-4291-8a93-81b3e38a70b7",
"metadata": {},
"outputs": [
@ -798,7 +801,7 @@
"[91 rows x 1 columns]"
]
},
"execution_count": 69 ,
"execution_count": 71 ,
"metadata": {},
"output_type": "execute_result"
}
@ -978,10 +981,865 @@
},
{
"cell_type": "code",
"execution_count": null ,
"execution_count": 181 ,
"id": "3c246940-1ad6-414f-b461-2d8ca7cd87f1",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" def single_quarter(table_name, col_list) {\n",
" \n",
" sel_col = array(ANY, 4 + size(col_list));\n",
" sel_col[0] = sqlCol('code');\n",
" sel_col[2] = sqlColAlias(<year(report_period)>, 'year');\n",
" \n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[i + 4] = sqlCol(col_list[i]);\n",
" }\n",
"\n",
" // 当季累计数据,作为下一季基准\n",
" sel_col[1] = sqlColAlias(sqlCol('report_period'), 'base_report_period');\n",
" sel_col[3] = sqlColAlias(<quarterOfYear(report_period) + 1>, 'quarter_of_year');\n",
" tbl_quarter_accum_base = sql(\n",
" select = sel_col,\n",
" from = table_name,\n",
" where = <quarterOfYear(report_period) < 4>\n",
" ).eval();\n",
"\n",
" // 从第二季开始,需要去匹配前一季累计基数\n",
" sel_col[1] = sqlColAlias(sqlCol('report_period'), 'current_report_period');\n",
" sel_col[3] = sqlColAlias(<quarterOfYear(report_period)>, 'quarter_of_year');\n",
" tbl_quarter_accum = sql(\n",
" select = sel_col,\n",
" from = table_name,\n",
" where = <quarterOfYear(report_period) > 1>\n",
" ).eval();\n",
"\n",
" // 单季流量,把非第一季的季报都要扣除前一季度的基数\n",
" sel_col[1] = sqlColAlias(sqlCol('current_report_period'), 'report_period');\n",
" sel_col[2] = sqlCol('year');\n",
" sel_col[3] = sqlCol('quarter_of_year');\n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[i + 4] = sqlColAlias(\n",
" expr(\n",
" sqlCol('tbl_quarter_accum_' + col_list[i]),\n",
" -,\n",
" sqlCol(col_list[i])\n",
" )\n",
" , col_list[i] + '_flux');\n",
" }\n",
" from_obj = ej(\n",
" tbl_quarter_accum_base, \n",
" tbl_quarter_accum, \n",
" `code`year`quarter_of_year, \n",
" `code`year`quarter_of_year);\n",
" tbl_quarter_flux = sql(\n",
" select = sel_col, \n",
" from = from_obj\n",
" ).eval();\n",
"\n",
" // 每年第一个季度\n",
" sel_col[1] = sqlCol('report_period');\n",
" sel_col[2] = sqlColAlias(<year(report_period)>, 'year');\n",
" sel_col[3] = sqlColAlias(<quarterOfYear(report_period)>, 'quarter_of_year');\n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[i + 4] = sqlColAlias(sqlCol(col_list[i]), col_list[i] + '_flux');\n",
" }\n",
" tbl_quarter1 = sql(\n",
" select = sel_col,\n",
" from = table_name,\n",
" where = <quarterOfYear(report_period) == 1>\n",
" ).eval();\n",
" \n",
" // 再拼接回第一季度(无需扣除基数的数据)\n",
" tbl_quarter_flux = unionAll(\n",
" tbl_quarter1, \n",
" tbl_quarter_flux\n",
" );\n",
" \n",
" return tbl_quarter_flux;\n",
" }\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 182,
"id": "981c8b85-a750-4d6b-bed9-c2567a95b2a3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>report_period</th>\n",
" <th>year</th>\n",
" <th>quarter_of_year</th>\n",
" <th>TOT_OPER_REV_flux</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-03-31</td>\n",
" <td>2019</td>\n",
" <td>1</td>\n",
" <td>1.032565e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-06-30</td>\n",
" <td>2019</td>\n",
" <td>2</td>\n",
" <td>2.021923e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>81</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-09-30</td>\n",
" <td>2019</td>\n",
" <td>3</td>\n",
" <td>2.183729e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>4.917866e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000558.SZ</td>\n",
" <td>2019-03-31</td>\n",
" <td>2019</td>\n",
" <td>1</td>\n",
" <td>2.361816e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>321</th>\n",
" <td>688396.SH</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>1.610869e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-03-31</td>\n",
" <td>2019</td>\n",
" <td>1</td>\n",
" <td>3.720237e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>325</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-06-30</td>\n",
" <td>2019</td>\n",
" <td>2</td>\n",
" <td>4.538674e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>324</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-09-30</td>\n",
" <td>2019</td>\n",
" <td>3</td>\n",
" <td>4.776034e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>323</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>4.816188e+07</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>326 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period year quarter_of_year TOT_OPER_REV_flux\n",
"0 000400.SZ 2019-03-31 2019 1 1.032565e+09\n",
"82 000400.SZ 2019-06-30 2019 2 2.021923e+09\n",
"81 000400.SZ 2019-09-30 2019 3 2.183729e+09\n",
"80 000400.SZ 2019-12-31 2019 4 4.917866e+09\n",
"1 000558.SZ 2019-03-31 2019 1 2.361816e+07\n",
".. ... ... ... ... ...\n",
"321 688396.SH 2019-12-31 2019 4 1.610869e+09\n",
"79 833874.NE 2019-03-31 2019 1 3.720237e+07\n",
"325 833874.NE 2019-06-30 2019 2 4.538674e+07\n",
"324 833874.NE 2019-09-30 2019 3 4.776034e+07\n",
"323 833874.NE 2019-12-31 2019 4 4.816188e+07\n",
"\n",
"[326 rows x 5 columns]"
]
},
"execution_count": 182,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"single_quarter(tmp_table, ['TOT_OPER_REV'])\").sort_values(['code', 'report_period'])"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "1ceea0a7-7218-4aa7-be8a-ebb655dcbc93",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" tmp_table = select * from pit_col_at_date(\n",
" \"is_common_ori\", \n",
" \"TOT_OPER_REV\", \n",
" 2021.03.14, \n",
" [2019.12.31, 2019.09.30, 2019.06.30, 2019.03.31], \n",
" 0) order by code\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "d01d6fc2-15ed-4e40-9181-0f3e3a96d2cb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>report_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>TOT_OPER_REV</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-04-10</td>\n",
" <td>1.015608e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-09-30</td>\n",
" <td>2019-10-12</td>\n",
" <td>5.238217e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-06-30</td>\n",
" <td>2019-08-24</td>\n",
" <td>3.054488e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-03-31</td>\n",
" <td>2019-04-26</td>\n",
" <td>1.032565e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000558.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-08-25</td>\n",
" <td>1.378479e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>333</th>\n",
" <td>831010.NE</td>\n",
" <td>2019-06-30</td>\n",
" <td>2019-08-09</td>\n",
" <td>1.970813e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>334</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-06-29</td>\n",
" <td>1.785113e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>335</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-09-30</td>\n",
" <td>2019-10-22</td>\n",
" <td>1.303494e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>336</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-06-30</td>\n",
" <td>2019-08-16</td>\n",
" <td>8.258911e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>337</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-03-31</td>\n",
" <td>2019-04-30</td>\n",
" <td>3.720237e+07</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>338 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period appear_at_date TOT_OPER_REV\n",
"0 000400.SZ 2019-12-31 2020-04-10 1.015608e+10\n",
"1 000400.SZ 2019-09-30 2019-10-12 5.238217e+09\n",
"2 000400.SZ 2019-06-30 2019-08-24 3.054488e+09\n",
"3 000400.SZ 2019-03-31 2019-04-26 1.032565e+09\n",
"4 000558.SZ 2019-12-31 2020-08-25 1.378479e+08\n",
".. ... ... ... ...\n",
"333 831010.NE 2019-06-30 2019-08-09 1.970813e+08\n",
"334 833874.NE 2019-12-31 2020-06-29 1.785113e+08\n",
"335 833874.NE 2019-09-30 2019-10-22 1.303494e+08\n",
"336 833874.NE 2019-06-30 2019-08-16 8.258911e+07\n",
"337 833874.NE 2019-03-31 2019-04-30 3.720237e+07\n",
"\n",
"[338 rows x 4 columns]"
]
},
"execution_count": 145,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"tmp_table\")"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "5ac22809-9ba9-4a01-b76a-591558c4cc52",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'< select symbol,date,cumsum(volume) as cumVol from tmp_tablef0e858a3837f0000 >'"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
"sql(select=sqlCol(['symbol', 'date', 'cumsum(volume) as cumVol']), from = tmp_table)\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "dc36ca56-07e0-4912-b5d2-da192a1c3c62",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'< select symbol,date,cumsum(volume) as cumVol from tmp_tablef0e858a3837f0000 >'"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"\"\"\n",
"sql(select=(sqlCol(`symbol),sqlCol(`date),sqlColAlias(<cumsum(volume)>, `cumVol)), from=tmp_table)\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 211,
"id": "c3be05b5-c9b9-4df5-8481-b3092c25125e",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" def yoy(table_name, col_list) {\n",
" sel_col = array(ANY, 4 + size(col_list));\n",
" sel_col[0] = sqlCol('code');\n",
" sel_col[3] = sqlColAlias(<quarterOfYear(report_period)>, 'quarter_of_year');\n",
" \n",
" // 上一年数据\n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[i + 4] = sqlColAlias(sqlCol(col_list[i]), col_list[i] + '_base');\n",
" }\n",
" sel_col[1] = sqlColAlias(sqlCol('report_period'), 'report_period_last_year');\n",
" sel_col[2] = sqlColAlias(<year(report_period) + 1>, 'year');\n",
" tbl_last_year = sql(\n",
" select = sel_col,\n",
" from = table_name\n",
" ).eval();\n",
"\n",
" // 本年度数据\n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[i + 4] = sqlCol(col_list[i]);\n",
" }\n",
" sel_col[1] = sqlColAlias(sqlCol('report_period'), 'report_period_current_year');\n",
" sel_col[2] = sqlColAlias(<year(report_period)>, 'year');\n",
" tbl_this_year = sql(\n",
" select = sel_col,\n",
" from = table_name\n",
" ).eval();\n",
" \n",
" // 计算同比增长率\n",
" sel_col = array(ANY, 4 + (3 * size(col_list)));\n",
"\n",
" sel_col[0] = sqlCol('code');\n",
" sel_col[1] = sqlColAlias(sqlCol('report_period_current_year'), 'report_period');\n",
" sel_col[2] = sqlCol('year');\n",
" sel_col[3] = sqlCol('quarter_of_year');\n",
" \n",
" for (i in 0..(size(col_list) - 1)) {\n",
" sel_col[3 * i + 4] = sqlCol(col_list[i] + '_base');\n",
" sel_col[3 * i + 5] = sqlCol(col_list[i]);\n",
" sel_col[3 * i + 6] = sqlColAlias(\n",
" expr(expr(sqlCol(col_list[i]), -, sqlCol(col_list[i] + '_base')), /, expr(abs, sqlCol(col_list[i] + '_base'))), \n",
" col_list[i] + '_yoy');\n",
" }\n",
" from_obj = ej(\n",
" tbl_last_year, \n",
" tbl_this_year, \n",
" `code`year`quarter_of_year, \n",
" `code`year`quarter_of_year);\n",
" \n",
" return sql(\n",
" select = sel_col,\n",
" from = from_obj).eval();\n",
" }\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 212,
"id": "63492d0c-c348-4e8b-a08b-5feb279cee5e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>report_period</th>\n",
" <th>year</th>\n",
" <th>quarter_of_year</th>\n",
" <th>TOT_OPER_REV_base</th>\n",
" <th>TOT_OPER_REV</th>\n",
" <th>TOT_OPER_REV_yoy</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>8.216559e+09</td>\n",
" <td>1.015608e+10</td>\n",
" <td>0.236051</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000400.SZ</td>\n",
" <td>2018-12-31</td>\n",
" <td>2018</td>\n",
" <td>4</td>\n",
" <td>1.033072e+10</td>\n",
" <td>8.216559e+09</td>\n",
" <td>-0.204648</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000558.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>7.024741e+08</td>\n",
" <td>1.378479e+08</td>\n",
" <td>-0.803768</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000558.SZ</td>\n",
" <td>2018-12-31</td>\n",
" <td>2018</td>\n",
" <td>4</td>\n",
" <td>1.324249e+09</td>\n",
" <td>7.024741e+08</td>\n",
" <td>-0.469530</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000677.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>7.068198e+08</td>\n",
" <td>7.906742e+08</td>\n",
" <td>0.118636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>688396.SH</td>\n",
" <td>2018-12-31</td>\n",
" <td>2018</td>\n",
" <td>4</td>\n",
" <td>5.875590e+09</td>\n",
" <td>6.270797e+09</td>\n",
" <td>0.067262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>831010.NE</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>2.936331e+08</td>\n",
" <td>3.552313e+08</td>\n",
" <td>0.209780</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>831010.NE</td>\n",
" <td>2018-12-31</td>\n",
" <td>2018</td>\n",
" <td>4</td>\n",
" <td>2.209252e+08</td>\n",
" <td>2.936331e+08</td>\n",
" <td>0.329106</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-12-31</td>\n",
" <td>2019</td>\n",
" <td>4</td>\n",
" <td>1.974978e+08</td>\n",
" <td>1.785113e+08</td>\n",
" <td>-0.096135</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>833874.NE</td>\n",
" <td>2018-12-31</td>\n",
" <td>2018</td>\n",
" <td>4</td>\n",
" <td>1.986075e+08</td>\n",
" <td>1.974978e+08</td>\n",
" <td>-0.005588</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>182 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period year quarter_of_year TOT_OPER_REV_base \\\n",
"0 000400.SZ 2019-12-31 2019 4 8.216559e+09 \n",
"1 000400.SZ 2018-12-31 2018 4 1.033072e+10 \n",
"2 000558.SZ 2019-12-31 2019 4 7.024741e+08 \n",
"3 000558.SZ 2018-12-31 2018 4 1.324249e+09 \n",
"4 000677.SZ 2019-12-31 2019 4 7.068198e+08 \n",
".. ... ... ... ... ... \n",
"177 688396.SH 2018-12-31 2018 4 5.875590e+09 \n",
"178 831010.NE 2019-12-31 2019 4 2.936331e+08 \n",
"179 831010.NE 2018-12-31 2018 4 2.209252e+08 \n",
"180 833874.NE 2019-12-31 2019 4 1.974978e+08 \n",
"181 833874.NE 2018-12-31 2018 4 1.986075e+08 \n",
"\n",
" TOT_OPER_REV TOT_OPER_REV_yoy \n",
"0 1.015608e+10 0.236051 \n",
"1 8.216559e+09 -0.204648 \n",
"2 1.378479e+08 -0.803768 \n",
"3 7.024741e+08 -0.469530 \n",
"4 7.906742e+08 0.118636 \n",
".. ... ... \n",
"177 6.270797e+09 0.067262 \n",
"178 3.552313e+08 0.209780 \n",
"179 2.936331e+08 0.329106 \n",
"180 1.785113e+08 -0.096135 \n",
"181 1.974978e+08 -0.005588 \n",
"\n",
"[182 rows x 7 columns]"
]
},
"execution_count": 212,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"yoy(tmp_table, ['TOT_OPER_REV'])\")"
]
},
{
"cell_type": "code",
"execution_count": 183,
"id": "5273ebfc-25bd-4b38-9605-d3109cf2280f",
"metadata": {},
"outputs": [],
"source": [
"sess.run(\"\"\"\n",
" tmp_table = select * from pit_col_at_date(\n",
" \"is_common_ori\", \n",
" \"TOT_OPER_REV\", \n",
" 2021.03.14, \n",
" [2019.12.31, 2018.12.31, 2017.12.31], \n",
" 0) order by code\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 184,
"id": "99af13cd-5918-4d21-9067-d3da86d19c15",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>code</th>\n",
" <th>report_period</th>\n",
" <th>appear_at_date</th>\n",
" <th>TOT_OPER_REV</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000400.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-04-10</td>\n",
" <td>1.015608e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000400.SZ</td>\n",
" <td>2018-12-31</td>\n",
" <td>2019-03-29</td>\n",
" <td>8.216559e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000400.SZ</td>\n",
" <td>2017-12-31</td>\n",
" <td>2018-03-24</td>\n",
" <td>1.033072e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000558.SZ</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-08-25</td>\n",
" <td>1.378479e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000558.SZ</td>\n",
" <td>2018-12-31</td>\n",
" <td>2019-04-26</td>\n",
" <td>7.024741e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>831010.NE</td>\n",
" <td>2018-12-31</td>\n",
" <td>2020-07-01</td>\n",
" <td>2.936331e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>269</th>\n",
" <td>831010.NE</td>\n",
" <td>2017-12-31</td>\n",
" <td>2020-07-01</td>\n",
" <td>2.209252e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>270</th>\n",
" <td>833874.NE</td>\n",
" <td>2019-12-31</td>\n",
" <td>2020-06-29</td>\n",
" <td>1.785113e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>271</th>\n",
" <td>833874.NE</td>\n",
" <td>2018-12-31</td>\n",
" <td>2020-06-29</td>\n",
" <td>1.974978e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>272</th>\n",
" <td>833874.NE</td>\n",
" <td>2017-12-31</td>\n",
" <td>2020-06-29</td>\n",
" <td>1.986075e+08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>273 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" code report_period appear_at_date TOT_OPER_REV\n",
"0 000400.SZ 2019-12-31 2020-04-10 1.015608e+10\n",
"1 000400.SZ 2018-12-31 2019-03-29 8.216559e+09\n",
"2 000400.SZ 2017-12-31 2018-03-24 1.033072e+10\n",
"3 000558.SZ 2019-12-31 2020-08-25 1.378479e+08\n",
"4 000558.SZ 2018-12-31 2019-04-26 7.024741e+08\n",
".. ... ... ... ...\n",
"268 831010.NE 2018-12-31 2020-07-01 2.936331e+08\n",
"269 831010.NE 2017-12-31 2020-07-01 2.209252e+08\n",
"270 833874.NE 2019-12-31 2020-06-29 1.785113e+08\n",
"271 833874.NE 2018-12-31 2020-06-29 1.974978e+08\n",
"272 833874.NE 2017-12-31 2020-06-29 1.986075e+08\n",
"\n",
"[273 rows x 4 columns]"
]
},
"execution_count": 184,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sess.run(\"tmp_table\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "87820a2a-1ddf-4950-b0d4-a3e7d4a61b16",
"metadata": {},
"outputs": [],
"source": []
}
],