了解stock_company
1 stock_company的基本信息
2 由于导入限制,把股票分成上交所和深交所分别导入
# username = 'root'
# password = '000000'
import pandas as pd
import tushare as ts
# from sqlalchemy import create_engine
# import pymysql
# pymysql.install_as_MySQLdb()
2.1 设置fields为交易所以外的信息
fields_list = ["ts_code", # 0 股票代码
"exchange", # 1 交易所代码 SSE上交所 SZSE深交所
"chairman", # 2 法人代表
"manager", # 3 总经理
"secretary", # 4 董秘
"reg_capital", # 5 注册资本
"setup_date", # 6 注册日期
"province", # 7 所在省份
"city", # 8 所在城市
"introduction", # 9 公司介绍
"website", # 10 公司主页
"email", # 11 电子邮件
"office", # 12 办公室
"employees", # 13 员工人数
"main_business", # 14 主要业务及产品
"business_scope", # 15 经营范围
]
fields = 'ts_code,exchange,chairman,manager,secretary,reg_capital,setup_date,province,city,introduction,website,email,office,employees,main_business,business_scope'
2.2 导入股票信息
pro = ts.pro_api()
2.3 分别取出上交所和深交所的信息并以dataframe的形式保存
# 一次只能取4000条,所以根据交易所分批提取
df_SZSE = pro.stock_company(exchange='SZSE' # 交易所代码 SZSE深交所
,fields=fields # 如果这个fields不写会出错
)
df_SZSE.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2437 entries, 0 to 2436
Data columns (total 16 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ts_code 2437 non-null object
1 exchange 2437 non-null object
2 chairman 2436 non-null object
3 manager 2408 non-null object
4 secretary 2435 non-null object
5 reg_capital 2437 non-null float64
6 setup_date 2437 non-null object
7 province 2437 non-null object
8 city 2437 non-null object
9 introduction 2433 non-null object
10 website 2401 non-null object
11 email 2432 non-null object
12 office 2437 non-null object
13 business_scope 2437 non-null object
14 employees 2434 non-null float64
15 main_business 2428 non-null object
dtypes: float64(2), object(14)
memory usage: 304.8+ KB
df_SSE = pro.stock_company(exchange='SSE' # 交易所代码 ,SSE上交所
# , fields=fields
)
df_SSE.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1871 entries, 0 to 1870
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ts_code 1871 non-null object
1 exchange 1871 non-null object
2 chairman 1871 non-null object
3 manager 1830 non-null object
4 secretary 1868 non-null object
5 reg_capital 1871 non-null