1
0
Files
finance/材料准备/股票基础信息.ipynb

563 lines
20 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-01-12T02:54:11.062677Z",
"start_time": "2025-01-12T02:54:11.058692Z"
}
},
"source": [
"import pandas as pd\n",
"import tushare as ts\n",
"\n",
"ts_pro = ts.pro_api(token=\"64ebff4fa679167600b905ee45dd88e76f3963c0ff39157f3f085f0e\")"
],
"outputs": [],
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-12T03:04:46.270874Z",
"start_time": "2025-01-12T03:04:45.589112Z"
}
},
"cell_type": "code",
"source": [
"stock_df = ts_pro.stock_basic(\n",
" fields=\"ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs,act_name,act_ent_type\")\n",
"stock_df.to_csv(\"../材料/股票基础信息.csv\", index=False)"
],
"id": "9bff0b9f37a2022a",
"outputs": [],
"execution_count": 11
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-12T04:06:31.055709Z",
"start_time": "2025-01-12T04:06:31.030421Z"
}
},
"cell_type": "code",
"source": [
"stock_df = pd.read_csv(\"../材料/股票基础信息.csv\")\n",
"stock_df"
],
"id": "c4addb03ad6dfd89",
"outputs": [
{
"data": {
"text/plain": [
" ts_code symbol name area industry fullname \\\n",
"0 000001.SZ 1 平安银行 深圳 银行 平安银行股份有限公司 \n",
"1 000002.SZ 2 万科A 深圳 全国地产 万科企业股份有限公司 \n",
"2 000004.SZ 4 国华网安 深圳 软件服务 深圳国华网安科技股份有限公司 \n",
"3 000006.SZ 6 深振业A 深圳 区域地产 深圳市振业(集团)股份有限公司 \n",
"4 000007.SZ 7 全新好 深圳 其他商业 深圳市全新好股份有限公司 \n",
"... ... ... ... ... ... ... \n",
"5383 920111.BJ 920111 聚星科技 NaN NaN 温州聚星科技股份有限公司 \n",
"5384 920116.BJ 920116 星图测控 NaN NaN 中科星图测控技术股份有限公司 \n",
"5385 920118.BJ 920118 太湖远大 NaN NaN 浙江太湖远大新材料股份有限公司 \n",
"5386 920128.BJ 920128 胜业电气 NaN NaN 胜业电气股份有限公司 \n",
"5387 689009.SH 689009 九号公司-WD 北京 摩托车 九号有限公司 \n",
"\n",
" enname cnspell market \\\n",
"0 Ping An Bank Co., Ltd. payh 主板 \n",
"1 China Vanke Co.,Ltd. wka 主板 \n",
"2 Shenzhen Guohua Network Security Technology Co... ghwa 主板 \n",
"3 Shenzhen Zhenye(Group) Co., Ltd. szya 主板 \n",
"4 Shenzhen Quanxinhao Co,.Ltd. qxh 主板 \n",
"... ... ... ... \n",
"5383 Wenzhou Juxing Science And Technology Co.,Ltd. jxkj 北交所 \n",
"5384 Geovis Insighter Technology Co.,Ltd. xtck 北交所 \n",
"5385 Zhejiang Taihu Yuanda New Material Co., Ltd thyd 北交所 \n",
"5386 Shengye Electric Co., Ltd. sydq 北交所 \n",
"5387 Ninebot Limited jhgs 科创板 \n",
"\n",
" exchange curr_type list_status list_date delist_date is_hs \\\n",
"0 SZSE CNY L 19910403 NaN S \n",
"1 SZSE CNY L 19910129 NaN S \n",
"2 SZSE CNY L 19910114 NaN N \n",
"3 SZSE CNY L 19920427 NaN S \n",
"4 SZSE CNY L 19920413 NaN N \n",
"... ... ... ... ... ... ... \n",
"5383 BSE CNY L 20241111 NaN N \n",
"5384 BSE CNY L 20250102 NaN N \n",
"5385 BSE CNY L 20240822 NaN N \n",
"5386 BSE CNY L 20241129 NaN N \n",
"5387 SSE CNY L 20201029 NaN NaN \n",
"\n",
" act_name act_ent_type \n",
"0 无实际控制人 无 \n",
"1 深圳市人民政府国有资产监督管理委员会 地方国企 \n",
"2 李映彤 民营企业 \n",
"3 深圳市人民政府国有资产监督管理委员会 地方国企 \n",
"4 王玩虹 民营企业 \n",
"... ... ... \n",
"5383 NaN NaN \n",
"5384 NaN NaN \n",
"5385 NaN NaN \n",
"5386 NaN NaN \n",
"5387 NaN NaN \n",
"\n",
"[5388 rows x 17 columns]"
],
"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>ts_code</th>\n",
" <th>symbol</th>\n",
" <th>name</th>\n",
" <th>area</th>\n",
" <th>industry</th>\n",
" <th>fullname</th>\n",
" <th>enname</th>\n",
" <th>cnspell</th>\n",
" <th>market</th>\n",
" <th>exchange</th>\n",
" <th>curr_type</th>\n",
" <th>list_status</th>\n",
" <th>list_date</th>\n",
" <th>delist_date</th>\n",
" <th>is_hs</th>\n",
" <th>act_name</th>\n",
" <th>act_ent_type</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000001.SZ</td>\n",
" <td>1</td>\n",
" <td>平安银行</td>\n",
" <td>深圳</td>\n",
" <td>银行</td>\n",
" <td>平安银行股份有限公司</td>\n",
" <td>Ping An Bank Co., Ltd.</td>\n",
" <td>payh</td>\n",
" <td>主板</td>\n",
" <td>SZSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>19910403</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>无实际控制人</td>\n",
" <td>无</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000002.SZ</td>\n",
" <td>2</td>\n",
" <td>万科A</td>\n",
" <td>深圳</td>\n",
" <td>全国地产</td>\n",
" <td>万科企业股份有限公司</td>\n",
" <td>China Vanke Co.,Ltd.</td>\n",
" <td>wka</td>\n",
" <td>主板</td>\n",
" <td>SZSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>19910129</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>深圳市人民政府国有资产监督管理委员会</td>\n",
" <td>地方国企</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000004.SZ</td>\n",
" <td>4</td>\n",
" <td>国华网安</td>\n",
" <td>深圳</td>\n",
" <td>软件服务</td>\n",
" <td>深圳国华网安科技股份有限公司</td>\n",
" <td>Shenzhen Guohua Network Security Technology Co...</td>\n",
" <td>ghwa</td>\n",
" <td>主板</td>\n",
" <td>SZSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>19910114</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>李映彤</td>\n",
" <td>民营企业</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000006.SZ</td>\n",
" <td>6</td>\n",
" <td>深振业A</td>\n",
" <td>深圳</td>\n",
" <td>区域地产</td>\n",
" <td>深圳市振业(集团)股份有限公司</td>\n",
" <td>Shenzhen Zhenye(Group) Co., Ltd.</td>\n",
" <td>szya</td>\n",
" <td>主板</td>\n",
" <td>SZSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>19920427</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>深圳市人民政府国有资产监督管理委员会</td>\n",
" <td>地方国企</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000007.SZ</td>\n",
" <td>7</td>\n",
" <td>全新好</td>\n",
" <td>深圳</td>\n",
" <td>其他商业</td>\n",
" <td>深圳市全新好股份有限公司</td>\n",
" <td>Shenzhen Quanxinhao Co,.Ltd.</td>\n",
" <td>qxh</td>\n",
" <td>主板</td>\n",
" <td>SZSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>19920413</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>王玩虹</td>\n",
" <td>民营企业</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",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\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>5383</th>\n",
" <td>920111.BJ</td>\n",
" <td>920111</td>\n",
" <td>聚星科技</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>温州聚星科技股份有限公司</td>\n",
" <td>Wenzhou Juxing Science And Technology Co.,Ltd.</td>\n",
" <td>jxkj</td>\n",
" <td>北交所</td>\n",
" <td>BSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>20241111</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5384</th>\n",
" <td>920116.BJ</td>\n",
" <td>920116</td>\n",
" <td>星图测控</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>中科星图测控技术股份有限公司</td>\n",
" <td>Geovis Insighter Technology Co.,Ltd.</td>\n",
" <td>xtck</td>\n",
" <td>北交所</td>\n",
" <td>BSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>20250102</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5385</th>\n",
" <td>920118.BJ</td>\n",
" <td>920118</td>\n",
" <td>太湖远大</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>浙江太湖远大新材料股份有限公司</td>\n",
" <td>Zhejiang Taihu Yuanda New Material Co., Ltd</td>\n",
" <td>thyd</td>\n",
" <td>北交所</td>\n",
" <td>BSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>20240822</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5386</th>\n",
" <td>920128.BJ</td>\n",
" <td>920128</td>\n",
" <td>胜业电气</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>胜业电气股份有限公司</td>\n",
" <td>Shengye Electric Co., Ltd.</td>\n",
" <td>sydq</td>\n",
" <td>北交所</td>\n",
" <td>BSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>20241129</td>\n",
" <td>NaN</td>\n",
" <td>N</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5387</th>\n",
" <td>689009.SH</td>\n",
" <td>689009</td>\n",
" <td>九号公司-WD</td>\n",
" <td>北京</td>\n",
" <td>摩托车</td>\n",
" <td>九号有限公司</td>\n",
" <td>Ninebot Limited</td>\n",
" <td>jhgs</td>\n",
" <td>科创板</td>\n",
" <td>SSE</td>\n",
" <td>CNY</td>\n",
" <td>L</td>\n",
" <td>20201029</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5388 rows × 17 columns</p>\n",
"</div>"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 73
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-12T04:08:38.611023Z",
"start_time": "2025-01-12T04:08:38.601858Z"
}
},
"cell_type": "code",
"source": [
"from datetime import datetime\n",
"\n",
"select_df = stock_df[[\"ts_code\", \"list_date\"]]\n",
"select_df[\"list_date\"] = pd.to_datetime(select_df[\"list_date\"], format=\"%Y%m%d\").dt.year\n",
"select_df = select_df[select_df[\"list_date\"] < datetime.now().year - 6]\n",
"select_df.rename(columns={\"ts_code\": \"code\", \"list_date\": \"listing_code\"}, inplace=True)\n",
"select_df.to_csv(\"../temp/select_stock.csv\", index=False)"
],
"id": "e46b093526873c23",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\lanyuanxiaoyao\\AppData\\Local\\Temp\\ipykernel_26584\\1081394513.py:4: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" select_df[\"list_date\"] = pd.to_datetime(select_df[\"list_date\"], format=\"%Y%m%d\").dt.year\n"
]
}
],
"execution_count": 77
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-12T04:08:54.938873Z",
"start_time": "2025-01-12T04:08:54.932403Z"
}
},
"cell_type": "code",
"source": [
"select_stock_df = pd.read_csv(\"../temp/select_stock.csv\")\n",
"select_df"
],
"id": "dc6a85e6ca6fbc14",
"outputs": [
{
"data": {
"text/plain": [
" code listing_code\n",
"0 000001.SZ 1991\n",
"1 000002.SZ 1991\n",
"2 000004.SZ 1991\n",
"3 000006.SZ 1992\n",
"4 000007.SZ 1992\n",
"... ... ...\n",
"4439 603991.SH 2017\n",
"4441 603993.SH 2012\n",
"4443 603997.SH 2015\n",
"4444 603998.SH 2014\n",
"4445 603999.SH 2015\n",
"\n",
"[3384 rows x 2 columns]"
],
"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>listing_code</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000001.SZ</td>\n",
" <td>1991</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>000002.SZ</td>\n",
" <td>1991</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>000004.SZ</td>\n",
" <td>1991</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>000006.SZ</td>\n",
" <td>1992</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>000007.SZ</td>\n",
" <td>1992</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4439</th>\n",
" <td>603991.SH</td>\n",
" <td>2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4441</th>\n",
" <td>603993.SH</td>\n",
" <td>2012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4443</th>\n",
" <td>603997.SH</td>\n",
" <td>2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4444</th>\n",
" <td>603998.SH</td>\n",
" <td>2014</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4445</th>\n",
" <td>603999.SH</td>\n",
" <td>2015</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3384 rows × 2 columns</p>\n",
"</div>"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 78
}
],
"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": 5
}