Tushare calls the Token password to obtain the stock data and save it as a CSV file and import it into Excel

There are many ways to obtain stock data sets through Python, which can be obtained by crawling stock-related websites or through the Tushare library.

Operation goal: Obtain and export a specific stock data set to a CSV file. (Take Kweichow Moutai as an example)
Insert picture description here

First register and log in at the upper right corner of Tushare

From here, enter directly → After Tushare
Insert picture description here
registration is completed, you can enter the personal homepage through the upper right corner. You can
Insert picture description here
get the Token password (that is, the interface command of api) on the personal homepage.
Insert picture description here
At this time, copy the token password, and we can obtain stock data in Python

import tushare as ts	# 导入tushare库
pro = ts.pro_api('我是token命令')	# 将复制好的token命令复制进api中

Successfully enter, instantiate df to receive stock data. Let’s take A-share king 600519 "Kweichow Moutai" as an example, and get data for a period of time~
from the beginning to the present (manual dog head)

df = pro.weekly(ts_code='600519.SH', start_data='', end_data='20201119')
# 获取 600519.SH 贵州茅台股票代码
print('贵州茅台df:\n', df)

Insert picture description here

At this point, we have obtained the weekly data set of Kweichow Moutai stocks from 2001 to the present, and then imported it into the CSV file.

df.to_csv('600519贵州茅台.csv')

Open the file and you're done!
Insert picture description here
Note: Tushare points are obtained. Generally, after completing the registration, you can achieve 120 points by modifying your personal information.
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/JasonZ227/article/details/109809435