Python Baostock库获取股票三年季度成长能力数据
import baostock as bs import pandas as pd
登陆系统
lg = bs.login()
显示登陆返回信息
print('login respond error_code:'+lg.error_code) print('login respond error_msg:'+lg.error_msg)
成长能力
growth_list = [] for year in range(2019, 2022): for quarter in range(1, 5): rs_growth = bs.query_growth_data(code='sh.600060', year=year, quarter=quarter) while (rs_growth.error_code == '0') & rs_growth.next(): growth_list.append(rs_growth.get_row_data()) result_growth = pd.DataFrame(growth_list, columns=rs_growth.fields)
打印输出
print(result_growth)
结果集输出到csv文件
result_growth.to_csv('D:\growth_data.csv', encoding='gbk', index=False)
登出系统
bs.logout()
原文地址: https://www.cveoy.top/t/topic/myye 著作权归作者所有。请勿转载和采集!