This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021

First, write first

Hi, I’m a cat lover and a tech lover.

Some time ago, I had a phone call with a brother, who made fun of his company and discussed the direction of his future work. It is really hard for a migrant worker. On the one hand, he is suffering from the “brainless” exploitation by some leaders of the company.

My brother also asked my opinion on the future employment direction and what programming to learn. I won’t go into details. My brother happens to be working in operations, and there is nothing else I can do to help, so I just want to write a Python series of operations.

This series has not been decided yet. It will focus on Python office automation. At least Python to Excel, World, Txt file/data processing, Python to system file processing, Python automatic mail, Python data crawling, Python simulation click login, Python data visualization, etc.

I hope you can draw some practical requirements from your own work, and I’ll help you solve problems, streamline your workflow, and improve your productivity with Python.

Two, knowledge point summary

2) Install jupyter Notebook, the most convenient Python editor. 3) Introduce and install common Python packages

Three, start using your head

3.1 Installing the Basic Python environment

3.1.1 Downloading the Python installation package

Mac comes with Python2.7, but with 3.0 and above now in the mainstream, it is true that Python3 is much easier to use and operate than Python2.

Computer browser to open the Official Python website:www.python.org/ Mouse over toDownloadsA dynamic box will appear showing the latest Version of Python, 3.9.5, and you can choose to download the Windows or Mac version (among other things).

Of course, I also recommend clicking on All releases and installing Python3.7.0, which is where you’ll be writing code throughout this tutorial series.

Of course, you can also directly access:www.python.org/downloads/r…Select an appropriate version to download. Generally, download the installation package. The two packages circled in red in the figure are MAC and Windows.

3.1.2 Installation Process in Windows

1) Click the downloaded installation package to enter the installation interface as shown in the following figure, and then select Install Launcher for all Users and Add Python 3.7 to PATH. This mainly involves installing the Python editor launcher and adding the Python environment to the system environment variables.

Check that box, then click Customize Installation, so you can Customize what to install and where to install it later. (For operators and other learners, the most important thing when installing software or environment is not to default the installation path. Generally, the default path is in DISK C, which will affect the smooth operation of the system.)

2) When you encounter a page that is not in the tutorial, click Next and go to the following page. Check the configuration you want to install according to the example shown in the picture. Click Browse and select the installation path. After the configuration is complete, clickInstallButton to install.

3) The whole installation process takes 3-5 minutes.

Once installed, clickCloseButton.

4) Windows open CMD and typepython --versionYou can see your installed Version of Python and typepythonTo enter the code editing environment, we can try to enterPrint (' Hello Python! ')And then press Enter, see what it looks like, typeThe exit ()You can exit the editing environment.

3.1.3 Mac Installation Process

1) The installation on Mac is relatively easy. Double-click the downloaded installation package and click all the wayNextorContinue toCan.

2) Mac usually has only one disk, so the default installation location is ok.

3) Click the installation button to complete the installation, and close the installation window after the same installation.

Once installed, Mac opens the terminal directly and enterspython3 --versionYou can see your installed Version of Python and typepython3, you can enter the code editing environment, we can try to inputPrint (' Hello Python! ')And press Enter to see what happens.Enter herepython3Python2 is different from Python2 on Mac.

Remember this is the first line of code you write, welcome to the code world.

3.2 Installing Jupyter Notebook, the most suitable Python editor for operation

3.2.1 Installing the Jupyter Notebook

Mac In terminal, enter:

pip3 install jupyter
Copy the code

In Windows, enter CMD:

pip install jupyter
Copy the code

The installation takes about 1 minute because there are many dependent packages.

To do this, you need to know and remember the PIP install package name for installing third-party packages in Python.

Here is also to introduce a way to install third-party packages through the domestic image source (faster installation), first or tell you the relevant operation instructions format:

PIP install -i Source address package name of the third-party imageCopy the code

If we install jupyter package above, we can change it to:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter
Copy the code

Some third-party mirror source addresses available in China:

Ali cloud http://mirrors.aliyun.com/pypi/simple/ https://pypi.mirrors.ustc.edu.cn/simple/ douban China university of science and technology (douban) http://pypi.douban.com/simple/ https://pypi.tuna.tsinghua.edu.cn/simple/ university of science and technology of China, tsinghua university http://pypi.mirrors.ustc.edu.cn/simple/Copy the code

3.2.2 Using the Jupyter Notebook

1) Enter the Jupyter Notebook in the TERMINAL (or in CMD in Windows) and enter

jupyter notebook 
Or python3 -m IPython notebook
Copy the code

The relevant service will launch and automatically call out to the browser, from which we can start writing code to improve our productivity.

2) Create a folder. Go to the desktop directory and create a folder.Name the folder aswork_projectIs used to store python scripts written later.

3) Create a new file to write Python code in the same way as abovework_projectCreate a new Python3 file under the Python3 folder to write the code.Click File to open the file menu, and then select Rename from the file menu to rename the newly created Python3 file (hereafter called notebook).So I’m going to call my first new file01_ Batch create folders or files under the specified folderYes, although we haven’t learned the basic knowledge of Python, it doesn’t affect us to run the code. I always think that learning in practice is the most effective. If you don’t understand it, write it down first and you can check it in the browser after class.

4) Implement batch new folder or file script under the specified folder

  • The basic introduction of buttons on the Jupyter code editing interface

1 Save the editing content 2 Add a code block 3 Cut the selected code block 4 Copy the selected code block 5 Paste the copied code block 6 Move the selected code block up/down 7 Run the selected code block 8 Pause the running code block 9 Restart the current running environment 10 Restart the current running environment, 11 Modify the format of the code block (default is the code block, can also select the tag, used to write description content)Copy the code
  • Create folders in batches under the specified folder

  • The results

  • Create text files in batches in the specified folder

  • The results

3.3 Introduction to and Installation of Common Python packages for Operation

  • Data processing category

* NUMpy: mainly used for data analysis and scientific computation, mainly includes multidimensional arrays and matrix data structures;

* Pandas: A library for handling data in Python. The library is called Series and DataFrame.

  • Excel to deal with

* XLRD: used to read Excel files; * XLWT: Used to write Excel files; Xlutils: Utility for manipulating Excel files, such as copying, splitting, filtering, etc. Openpyxl: Used for reading and writing Excel files.

  • Word processing

* Python-docx: a Python library for creating and updating Word (.docx) files.

  • PDF processing

PyPDF4: a pure Python PDF that can split, merge, merge libraries, and convert PDF files to pages; * PDfMiner: Is a text extraction tool for PDF documents; * PDfKit: Can convert text, HTML, etc to PDF.

  • Text processing

* re: Regular expression module that extracts the target content from a string.

  • The crawler

* Requests: basic crawler libraries for get and POST requests. Bs4 is a library that can easily pull information from web pages. Selenium: Enables automatic interaction with web pages, such as automated clicking.

  • Mail processing

* Yamail: A module for sending emails that supports message content formatting (such as Markdown format).

  • Data visualization

* Matplotlib: the most widely used plotting package that can create most types of charts, such as bar charts, scatter charts, bar charts, pie charts, stack charts, 3D charts and map charts.* PyEcharts: is a library for generating Echarts diagrams with better visualizations than Matplotlib.Bokeh: Interactive browser visualization library, more gorgeous.

“*” indicates more commonly used packages. For package installation, follow the method of installing third-party packages in 3.2.1. If you encounter any problems, you can leave a comment in the comment section.

Four, practise

1. Exercise operation:In the Jupyter Notebook and create it on the desktop before you delete itwork_projectFolder, and create a new folderOperating learning PythonAnd enter the directory to create two new files:Day01 fixes the environmentandwork_project.Day01 fixes the environmentIn the record of their own study notes, practice screenshots;work_projectWhere all the code scripts of this series are stored. (As shown below)

2. Lay the foundation: Install all of the above mentioned common Python packages in the Python environment, and choose any package to explore, understand its basic usage.

See you next time. I’m a cat lover and a tech lover. If you find this article helpful, please like, comment and follow me!