Peeping into the future is not a dream, python data analysis is easy to achieve

Java architects Alliance 2021-02-23 01:45:05
peeping future dream python data


What is programming , To put it simply, it's actually to write code ? That's such a boring job , Why do so many people want to enter this industry ? Actually , As a professional for many years “ Senior cv The engineer ”, One College entrance examination 6 Institutions , Every institution 6 A professional , There's no one who has anything to do with computers , Up to now, I have completely fallen in love with the computer industry , It's very simple , When you see yourself writing countless lines of code , Finally, it shows the functions one by one demo, Help a lot of people save a lot of practice ,demo Isn't it our project to unite ? Right , In fact, the charm of programming is to teach the computer to help you do all kinds of difficult things in the shortest time , And then help others

Because I wrote some for you before Python Reptiles Related cases of , It's very hot recently python What can I do for you ? It doesn't seem to have much to do with my work , Take a moment to look down , except Artificial intelligence , big data Beyond such high-end disciplines , How does he help you in your daily life


First knowledge of data analysis


If you're an accountant , Administration , Journalism , In medicine and other professions, you can use data analysis to help you sort out and report a lot of data

What era is this , This is an age of data , You have to deal with a lot of data reports every day 、 Reports, even customer relationship news, etc , however , There is a saying. , The number is not as good as the watch , Chart is not as good as table , I don't know if your year-end report is finished , Let me take this year-end report as an example , In fact, it's plain , What the year-end report should do is to show the data of the whole year and the data of the future ? And the data , When we finish the presentation , What can you do , The previous data can be directly used out of the box , adopt excel Wait for the operation , Even though it's a little more troublesome , But it's also possible to make some forms (ps:office Except for the gods , I this office Small slag , Don't even think about it ), But when the amount of data comes up ,office Not even the great God , What's more, with the help of previous data , Show the future . What the year-end report decides is the amount of the year-end bonus , And your career development in the coming year , So at this point , Through data processing, filtering and visual analysis , Come to the conclusion , Help you make decisions

With all of you , The time to feel your head and make decisions is over , This is the age of data driven decision making , Or you write a year-end report , The boss asked you how you got this conclusion , You said you felt it ? If your whole report data derivation conclusion is in place , Are you more likely to add year-end bonus to your year-end report ?

So much for that ,python What can I do for you ?

Look directly at the renderings


That's our most basic , Draw our icon through the corresponding data , The source of the data is simple , It's America that can be downloaded from the Internet gdp Data graph , But if I really want you to do it , You're going to have a headache , If you don't believe it, you can try

This is the data format :


Data source address :


I think it will take a lot of time just for you to paste and organize the data , however , The same thing , If you give it all to python To do it , How much time can I save you ? The first is our data acquisition



Crawler gets data code

# -*- coding: utf-8 -*-
import requests
from lxml import etree
import openpyxl

def get_html(url):
   headers = {
       "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36"
   html = requests.get(url)
   return html.text

def parse_content(content):
   e = etree.HTML(content)
   year_list = e.xpath("//tr/td[1]/text()")
   gdp_list = e.xpath("//tr/td[2]/text()")
   percents_list = e.xpath("//tr/td[3]/text()")
   year_list = list(filter(is_correct,year_list))
   year_list = list(map(int,year_list))
   gdp_list = list(map(extract, gdp_list))
   percents_list = list(map(delete_char,percents_list))

def save_data(year_list,gdp_list,percents_list):
   wk = openpyxl.Workbook()
   sheet =
   for i in range(len(year_list)):

def extract(s):
   return int(s[s.find('(')+1:s.rfind(')')].replace(",",""))

def delete_char(s):
   return float(s.replace("%",""))

def is_correct(s):
   s = s.strip()
   if s:
       return s.isdigit()
   return False

if __name__ == '__main__':
   content = get_html("")


When our data is obtained and sorted according to certain rules , Specific steps , You can refer to my previous python Crawler related content

And when the data is available , We can analyze the data according to these data , I'll just show you some key codes , I have uploaded the detailed code to my code cloud warehouse , Friends in need can take their own :

The warehouse address is here



Data analysis code


# Draw America GDP Change chart import xlrdimport matplotlib.pyplot as pltimport numpy as np

#1、 get data

#print(data.sheet_names())   # Read the data in the table excel=data.sheet_by_name('Sheet')

#2、 Charting

   # Set the font 
   # Draw area 
   plt.figure(figsize=(16,9))plt.title(" The United States gdp Change chart ")    
   # structure xy Axis 
   plt.xlabel(' year ')
   plt.ylabel('GDP( One trillion )')

#3、 The data fills the chart

# adopt for Loop through the data in each cell and store it accordingly 
year_list=[]for i in range(excel.nrows):    
# Adds data from a cell to the list    
# !!!!!!!! The most important point : Merge data together to form a multidimensional array arr=np.array(list(zip(year_list,gdp_list,percent_list)),dtype=np.float64)

#4、 Exhibition

plt.plot(arr[:,[0]],arr[:,[2]],"--r",label=" Market share ")


Be careful :

If you have the latest version numpy, But you also used the previous online tutorial , Will report a mistake


No problem , take it easy , No impact on operation , Just said it would report a mistake , The method of improvement is also very simple

The old version of the code says np.float To define the data type , After improvement, it's like this


That's all right.


This is also a problem brought about by code updating , A lot of previous code can't be used or error is reported , This question is very unfriendly for beginners , We may have to go through a lot of information , But I don't know , The reasons and answers are shown on the console





Here are some new year's benefits for you , There is a need for these learning materials , You can pay attention to me , Click add background assistant :python1180 Can get

This is my new year's benefit to you



本文为[Java architects Alliance]所创,转载请带上原文链接,感谢

  1. Python 空间绘图 - 房价气泡图绘制
  2. Translation: practical Python Programming 02_ 02_ Containers
  3. Research on Portfolio Optimization Based on particle swarm optimization
  4. Ubuntu deploying Django project
  5. Two years of Java, write Python and go without byte beating
  6. Translation: practical Python Programming 02_ 02_ Containers
  7. So learn python, grandfather learned! Introduction to super simple Python
  8. python3 多线程 与 mongo亿级消费日志数据 新鲜demo 【优化第一版】
  9. Summary of Chinese word segmentation based on Jieba
  10. I've heard it n times, but I'm not impressed. After reading this, you'll understand
  11. Summary of Chinese word segmentation based on Jieba
  12. From movie art to Python code to realize God's reverse thinking mode
  13. Summary of Chinese word segmentation based on Jieba
  14. ARIMA模型预测CO2浓度时间序列-python实现
  15. Python belongs to back-end development or front-end development? Introduction to Python!
  16. python isinstance()
  17. I've heard it n times, but I'm not impressed. After reading this, you'll understand
  18. This article will familiarize you with the transformation process of Python - & gt; cafe - & gt; om model
  19. 如何用Python一键修改上万个文件名
  20. One day quick start to Python
  21. Python 学习笔记: List
  22. 翻译:《实用的Python编程》02_03_Formatting
  23. Is there any age requirement for learning Python? Is 30 OK?
  24. Professor Tsinghua! The most complete Python tutorial in 12 hours (free sharing at the end of the article)
  25. Using Python to develop defi project
  26. Detailed explanation of Python function
  27. Python 可变类型作为函数默认参数时的副作用
  28. What do Python engineers do? What's their future?
  29. 这是我见过最好的Python教程:十分钟带你认识Python
  30. Python欢喜冤家:爬虫与反爬虫带着处理方案来给大家拜年了
  31. Python - zip() function
  32. 写Python会遇到如下的错误:ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package
  33. Python类的调用以及私有和公有属性方法的调用
  34. Python类的专有方法
  35. Python基础之:数字字符串和列表
  36. How did Python pioneers evaluate this language on their 30th birthday?
  37. Python基础之:数字字符串和列表
  38. Python基础之:数字字符串和列表
  39. 窥探未来不是梦,python数据分析轻松实现
  40. This article will familiarize you with the transformation process of Python - & gt; cafe - & gt; om model
  41. 阿里、华为Python工程师总结的实用技巧,只有你还没看?
  42. 酸了!看到抖音上Python程序员晒得工资条......
  43. Python基础之:数字字符串和列表
  44. Importing excel into database adaptively by Python
  45. Python安装教程
  46. Python安装教程
  47. From Xiaobai to master, here is a guide to pandas
  48. [Python] drawing method of stem leaf diagram and compound pie diagram
  49. Drawing of Python geoplot spatial kernel density estimation map
  50. Python Seaborn economist's classic chart imitation
  51. Python space drawing - regionmask mask operation example
  52. Python space drawing - cartopy longitude and latitude add
  53. Python pykrige package Kriging interpolation calculation and visual rendering
  54. Python batch resampling, mask, slope extraction
  55. Python - Analysis of reachable circle of multiple traffic modes
  56. Python space drawing bubble drawing
  57. Python 3 multithreading and Mongo 100 million consumption log data fresh demo
  58. ARIMA model for predicting time series of CO2 concentration
  59. python isinstance()
  60. How to modify tens of thousands of file names with one key in Python