How to realize Visualization data in Python
In this issue, the editor will bring you about how to achieve visual data in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Crawler code
Request web page
Import requestsurl = 'https://xueqiu.com/service/v5/stock/screener/quote/list'response = requests.get (url=url, params=params, headers=headers, cookies=cookies) html_data = response.json () # for students who want the complete code, please follow the official Wechat account: squirrels love biscuits # send a message' stock'to get it.
Parsing data
Data_list = html_data ['data'] [' list'] for i in data_list: dit = {} dit ['stock symbol'] = I ['symbol'] dit [' stock name'] = I ['name'] dit [' current price'] = I ['current'] dit [' up and down'] = I ['chg'] dit [' up and down /%'] = I ['percent'] Dit ['year to date /%'] = I ['current_year_percent'] dit [' turnover'] = I ['volume'] dit [' turnover'] = I ['amount'] dit [' turnover /%'] = I ['turnover_rate'] dit [' P / E] = I ['pe_ttm'] dit [' dividend yield /%'] = I ['dividend_yield'] Dit ['market capitalization'] = I ['market_capital'] print (dit)
Save data
Import csvf = open ('stock data .csv', mode='a', encoding='utf-8-sig', newline='') csv_writer = csv.DictWriter (f, fieldnames= ['stock symbol', 'stock name', 'current price','up and down amount','up and down /%', 'year to date /%', 'volume', 'turnover', 'turnover /%', 'price / earnings ratio TTM',' dividend yield /%' 'Market value']) csv_writer.writeheader () csv_writer.writerow (dit) f.close ()
Data analysis code
C = (Bar () .add _ xaxis (list (df2 ['stock name'] .values)) .add _ yaxis ("stock volume situation", list (df2 ['volume] .values)) .set _ global_opts (title_opts=opts.TitleOpts (title= "volume chart-Volume chart"), datazoom_opts=opts.DataZoomOpts (),) .render ("data.html"))
The above is how to achieve visual data in the Python shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.