The ninth day of preparation Notes for national computer grade examination level II Python (September 2021)

Posted by dlgilbert on Fri, 19 Nov 2021 21:20:01 +0100

Python language programming - MOOC lecture notes week 9

Knowledge point 1

Data analysis of Python Library

  • Numpy: the most basic library for expressing N-dimensional arrays
  • Python interface, C language, excellent computing speed
  • Python is a basic library for data analysis and scientific computing, supporting Pandas, etc
  • It provides direct matrix operation, broadcast function, linear algebra and other functions
  • Numpy: the most basic library for expressing N-dimensional arrays
  • NumPy Library:
  • Pandas:Python data analysis high-level application library
  • It provides simple and easy-to-use data structure and data analysis tools
  • Understand the relationship between data type and index. Operating index is operating data
  • Python's main data analysis library is developed based on Numpy
  • Series = index + one-dimensional data
  • DataFrame = row column index + 2D data
  • Pandas Library:
  • SciPy: mathematical, scientific and Engineering Computing Library
  • It provides a number of mathematical algorithms and engineering data operation functions
  • Similar to Matlab, it can be used in applications such as Fourier transform, signal processing and so on
  • Python's main scientific computing library is developed based on Numpy
  • SciPy:

Data visualization of Python Library

  • Matplotlib: high quality 2D data visualization Library
  • More than 100 kinds of data visualization effects are provided
  • Call each visualization effect through matplotlib.pyplot sub library
  • Python's main data visualization library is developed based on Numpy
  • Matplotlib:
  • Seaborn: statistical data visualization Library
  • A batch of high-level statistical data visualization display effects are provided
  • It mainly displays the distribution, classification and linear relationship among data
  • It is developed based on Matplotlib and supports Numpy and Pandas

  • Mayavi: 3D scientific data visualization Library
  • It provides a batch of easy-to-use 3D scientific computing data visualization display effects
  • The current version is Mayavi2, the main third-party library for 3D visualization
  • Support Numpy, TVTK, Traits, envision and other third-party libraries
  • Mayavi:

Text processing of Python Library

  • PyPDF2: toolset for processing pdf files
  • It provides a calculation function for batch processing PDF files
  • Support information acquisition, file separation / integration, encryption and decryption, etc
  • Fully implemented in Python language, no additional dependency and stable function
from PyPDF2 import PdfFileReader,PdfFileMerger
  • PyPDF2:
  • NLTK: natural language text processing third party Library
  • It provides a number of simple and easy-to-use natural language text processing functions
  • Support language text classification, marking, syntax, semantic analysis, etc
  • The best Python natural language processing library
from nltk.corpus import treebank
  • Python docx: create or update third-party libraries for Microsoft Word files
  • It provides the calculation function of creating or updating. Doc. Docx and other files
  • Add and configure paragraphs, pictures, tables, text, etc., with comprehensive functions
from docx import Document
document = Document()
document.add_heading('Document Title',0)
p=document.add_paragraph('A plain paragraph having some ')

Machine learning of Python Library

  • Scikit learn: tool set of machine learning methods
  • Provide a number of unified machine learning method function interfaces
  • It provides computing functions such as clustering, classification, regression and reinforcement learning
  • The most basic and excellent Python third-party library for machine learning
  • Scikit-learn:
  • Tensorflow: machine learning computing framework behind alphago
  • Open source machine learning framework promoted by Google
  • Based on the data flow graph, the graph nodes represent operations and edges represent tensors
  • A way to apply machine learning methods to support Google's artificial intelligence applications
import tensorflow as tf
init = tf.global_variables_initializer()
  • TensorFlow:
  • MXNet: deep learning computing framework based on Neural Network
  • It provides scalable neural network and deep learning computing function
  • It can be used in many fields such as automatic driving, machine translation, language recognition and so on
  • Python's most important deep learning computing framework
  • MXNet:

Example Holland personality analysis

problem analysis

  • Holland personality analysis
  • Holland believes that there should be an internal correspondence between personality interest and occupation
  • Personality classification: research type, artistic type, social type, enterprise type, traditional type and reality type
  • Occupation: engineer, experimenter, artist, salesman, recorder, social worker
  • Holland personality analysis radar chart
  • Requirements: radar chart to verify Holland's personality analysis
  • Input: survey data of various occupational groups combined with interests
  • General radar mapping: matplotlib Library
  • Professional multidimensional data representation: numpy Library
  • Output: radar chart

Example display

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
radar_labels=np.array(['Research type(I)','Artistic type(A)','Social type(S)','enterprise class(E)','Conventional type(C)','Realistic type(R)'])
			   [0.34,0.31,0.38,0.40,0.92,0.28]])    #Data value
data_labels=('artist','Experimenter','engineer','salesman','social worker','Recorder')
plt.figtext(0.52,0.95,'Holland personality analysis',ha='center',size=20)

Output results:

infer other things from one fact

  • Goal + immersion + proficiency
  • The goal of programming: find the goal of interest and find (wa) and (jue)
  • Immersion in programming: find realizable methods and think about them
  • Proficiency in programming: practice, practice, practice again, proficiency

Knowledge point 2

Python library web crawler

  • Requests: the most friendly web crawler Library
  • It provides a simple and easy-to-use HTTP protocol like web crawler function
  • Support connection pool, SSL, Cookies.HTTP(S) proxy, etc
  • Python's main page level Web crawler Library
import requests
  • Requests:
  • Scrapy: excellent web crawler framework
  • It provides the framework function and semi-finished product of building web crawler system
  • Support batch and regular web page crawling, provide data processing flow, etc
  • Python is the most important and professional web crawler framework
  • Scrapy: Python data analysis high level application library
  • pyspider: a powerful Web page crawling system
  • It provides a complete web page crawling system construction function
  • Support database backend, message queue, priority, distributed architecture, etc
  • Python's important third-party library of web crawlers
  • pyspider:

Web information extraction of Python Library

  • Beautiful soup: parsing library for HTML and XML
  • It provides the function of parsing Web information such as HTML and XML
  • Also known as beautiful soup 4 or bs4, it can load a variety of parsing engines
  • It is often used with web crawler libraries, such as scrape, requests, etc
  • Beautiful Soup:
  • Re: regular expression parsing and processing library
  • Provides a number of general functions for defining and parsing regular expressions
  • It can be used in various scenarios, including fixed-point Web information extraction
  • Python is one of the most important standard libraries without installation
  • Re:
  • Python Goose: feature library for extracting article type Web pages
  • It provides the function of extracting metadata such as article information / video in Web pages
  • For specific types of Web pages, the application coverage is wide
  • Python's main Web information extraction Library
from goose import Goose
  • Python-Goose: https//

Web site development of Python Library

  • Django: the most popular Web application framework
  • It provides the basic application framework for building Web system
  • MTV mode: model, template, views
  • Python is the most important Web application framework, a slightly complex application framework
  • Django:
  • Pyramid: a moderate scale Web application framework
  • It provides a simple and convenient application framework for building Web system
  • Medium size, moderate scale, suitable for rapid construction and moderate expansion of class applications
  • Python product level Web application framework is simple to start and has good scalability
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
	return Response('Hello World!')
if __name__ =='__main__':
	with Configurator() as config:
  • Pyramid:
  • Flask: Web application development micro framework
  • It provides the simplest application framework for building Web system
  • Features: simple, small-scale, fast
  • Django > pyramid > flask OK
from flask import Flask
app = Flask(__name__)
def hello_world():
	return 'Hello,World!'
  • Flask:

Network application development of Python Library

  • WeRoBot: WeChat official account development framework
  • It provides the function of parsing wechat server messages and feedback messages
  • An important technical means of establishing wechat robot
import werobot
robot =werobot.WeRoBot(token='tokenhere')
def hello(message):
	return 'Hello World!'
  • WeRoBot:
  • aip: Baidu AI open platform interface
  • Python function interface for accessing Baidu AI service is provided
  • Voice, face, OCR, NLP, knowledge map, image search and other fields
  • Python is the main way of Baidu AI application
  • aip:
  • MyQR: QR code generation third party Library
  • It provides a series of functions for generating QR codes
  • Basic QR code, art QR code and dynamic QR code
  • MyQR:

Graphical user interface of Python Library

  • Pyqt5: Python interface of Qt development framework
  • Provides a Python API interface for creating Qt5 programs
  • Qt is a very mature cross platform desktop application development system with complete GUI
  • Recommended Python GUI development third-party library
  • PyQt5:
  • wxPython: cross platform GUI development framework
  • Provides a cross platform GUI development framework dedicated to Python
  • Understand the relationship between data type and index. Operating index is operating data
  • Python's main data analysis library is developed based on Numpy
import wx
frame=wx.Frame(None,wx.ID_ANY,"Hello World")
  • wxPython:
  • PyGObject: develop GUI function library using GTK +
  • It provides the function of integrating GTK +, WebKit GTK + and other libraries
  • GTK: a cross platform GUI framework for user graphical interface
  • Example: Anaconda uses this library to build GUI
import gi
from gi.repository import Gtk
window =Gtk.Window(title="Hello World")
  • PyGObject:

Game development of Python Library

  • PyGame: a simple game development library
  • It provides a simple game development function and implementation engine based on SDL
  • Understand the response mechanism of the game to external input and the role construction and interaction mechanism
  • The main third-party library for getting started with Python games
  • PyGame:
  • Panda3D: open source, cross platform 3D rendering and game development library
  • A 3D game engine that provides Python and C + + interfaces
  • Support many advanced features: normal map, gloss map, cartoon rendering, etc
  • Jointly developed by Disney and Carnegie Mellon University
  • Panda3D:
  • cocos2d: a framework for building interactive applications of 2D games and graphical interfaces
  • It provides the graphics rendering function of game development based on OpenGL
  • It supports GPU acceleration and adopts tree structure to manage game object types hierarchically
  • Suitable for 2D professional game development
  • cocos2d:

Virtual reality of Python Library

  • VR Zero: Python library for developing VR applications on raspberry pie
  • It provides a large number of functions related to VR development
  • VR development library for raspberry pie supports miniaturization of equipment and simplified configuration
  • It is very suitable for beginners to practice VR development and application

  • VR Zero:
  • Pyovr: the Python development interface of oculus rift
  • Python development library for Oculus VR device
  • Based on mature VR equipment, provide a full set of documents and industrial application equipment
  • An idea of Python + virtual reality exploration
  • pyovr:
  • Wizard: General VR development engine based on Python
  • Professional enterprise virtual reality development engine
  • Provide detailed official documents
  • It supports a variety of mainstream VR hardware devices and has certain universality
  • Vizard:

Graphic art of Python Library

  • Quads: the art of iteration
  • The image is divided into four iterations to form a pixel wind
  • Dynamic or static images can be generated
  • Easy to use, with a high degree of display
  • Quads:
  • ascii_art: ASCII Art Library
  • Convert normal pictures to ASCII art style
  • The output can be plain text or color text
  • It can be output in picture format
  • ascii_art:
  • turtle: turtle drawing system
  • Random Art
  • turtle:

Instance rose drawing

problem analysis

  • Rose drawing
  • Rendering mechanism: rendering of basic graphics of turtle
  • Drawing ideas: vary from person to person
  • The world is as big as the thought is
#The code is as follows:
import turtle as t
#Define a curve drawing function
def DegreeCurve(n,r,d=1):
	for i in range(n):
#Initial position setting
s=0.2    #size
#Draw flower shape
#Draw flower branch shape
#Draw a green leaf
#Draw another green leaf

infer other things from one fact

  • Art is to programming, and design is to programming
  • Art: thought first, programming is the means
  • Design: ideas are as important as programming
  • Engineering: programming first, thought second
  • Programming is not important, thought is important!
  • Know yourself: clarify your goals and have your own thoughts (Ideas)
  • Methods and methods: programming is only a means. Be proficient and prepare for a rainy day to serve the thought
  • Who to program for: combine self-development with the development of the motherland to create real value

Week 9 test questions

Programming problem

Question 1 acquisition of basic system information

Title Description: obtain the recursion depth of the system, the current execution file path, the maximum UNICODE coding value of the system, and print out.
Output format:
Reclimit: < depth >, expath: < file path >, Unicode: < maximum encoding value >
Tip: please find the above functions in the sys standard library
Input example: None
Output example: reclimit: 500, exit: / bin / python, Unicode: 1411

The code is as follows:
import sys
print("RECLIMIT:{}, EXEPATH:{}, UNICODE:{}".format(sys.getrecursionlimit(), sys.executable, sys.maxunicode))

Two dimensional data table output

Topic Description: tabulate can output two-dimensional data in tables. It is an excellent third-party computing ecosystem in Python. ‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬ ‪‬‪‬‪‬‮‬‪‬‫‬
Refer to the data and code given in the programming template, write a program, and be able to output the tabular data of the following style effects.

from tabulate import tabulate
data = [ ["Beijing University of Technology", "985", 2000], \
         ["Tsinghua University", "985", 3000], \
         ["Dalian University of Technology", "985", 4000], \
         ["Shenzhen University", "211", 2000], \
         ["Shenyang University", "Provincial capital", 2000], \
print(tabulate(data, tablefmt="grid"))

Topics: Python