In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to achieve Python capture data to visualization of the whole process, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
1. Climb the target website: performance forecast _ data center _ flush finance and economics
(ps:headers will not be set up. You can read this article: Python uses requests.get to get the content of the web page is empty.')
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport reimport requests## guides headers= {'Accept':' text/html,*/* in advance of various packages that may be used. Qreply 0.01, 'hexin-v':' A2C11EVPFXAhNKl0PUpM6xp8MWU2aUUO5kMury YOdpwLngMrQpTgnkUwzZdaMpfilling, 'Referer':' http://data.10jqka.com.cn/financial/yjyg/', 'Cookie':' For 'User-Agent':', fill in'} url= "http://data.10jqka.com.cn/ajax/yjyg/date/2021-12-31/board/ALL/field/enddate/order/desc/page/{}/ajax/1/free/1/"result =''for i in range (1, 5): result + = requests.get (url.format (I), headers=headers) .textresult
Crawl succeeded, check the data:
2. Get the serial number, stock symbol, etc. Index = re.findall ('(. *)', result) index
148 pieces of data meet expectations, continue to look at the stock symbol (here use regular expression query, you can see this article explains regular expressions: regular expressions + common examples)
Stock_code = re.findall ('class= "stockCode" > (. *)', result) print (stock_code)
3. Composition DataFramedata = pd.DataFrame ({"stock_code": stock_code, "stock_name": stock_name, "performance": performance, "summary": summary}, index=index) data
Combination is successful
4. Processing data
Use regularization to filter out net profit and growth
Data ['start_profit'] = data [' summary'] .str.extract ('(- {0summary' 1}\ d {0 10}\ d {0 10}) data ['end_profit'] = data [' summary'] .str.extract ('to (- {0 1}\ d {0prit 10}\.) data ["start_range"] = data ['summary'] .str.extract (' (\ d {0prit 5})) \. {0summary' 1}\ d {0summary' 5})%') + "%" data ["end_range"] = data ['summary'] .str.extract (' to (\ d {0summary' 5})%') + "%" data.head ()
Judge profitability:
Def if_profit (x): if x in ['performance forecast decline', 'performance increase', 'performance decline', 'performance profit forecast', 'performance increase', 'expected turnaround']: return 1 if x in ['expected loss reduction', 'uncertainty', 'performance loss forecast', 'expected loss increase' 'expected continued loss']: return-1 return 0data ['is_profit'] = data.apply (lambda x: if_profit (x ["performance"]), axis=1) data.head () # # calculate profit yingli = (data [' is_profit'] = = 1). Sum () yingli## loss how much kuisun = (data ['is_profit'] =-1). Sum () kuisun
Visualization is achieved by drawing a pie chart:
Plt.pie ([yingli,kuisun], labels= ['profit', 'loss'], autopct='%.2f%%') font= {"family": "kaiti", "size": "15"} plt.rc ("font", * * font) plt.title
The above content is how to realize the whole process of Python grabbing data to visualization. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.