In the previous section, we described how to import and use the standard library that comes automatically when you install Python. As I explained there, some libraries are not installed by default, and I called them ** external libraries **. This time I would like to explain how to install this external library.
External libraries are libraries developed by engineers around the world. These libraries are registered in the following repository called ** PyPI **. https://pypi.org/
It's hard to find the library you need because PyPI contains information about libraries around the world. Therefore, ** pip (package management system) ** is used when installing the library (package).
This pip allows you to install packages, but pip also has the following features:
--List management of already installed packages is possible --If a package is ** dependent ** on another package, that dependent package can be installed with it --Search for installable packages
Of these, ** installing while checking package dependencies ** is an important feature of pip. For example, there is a package called ** pandas ** used for AI data analysis, but if you install this, a package called ** numpy ** that automatically calculates matrices will also be installed. In this way, it is an important function of pip to install the necessary packages when installing a certain package.
Install the library using the command pip. I will not do it this time, but </ font> You can actually install it from the following location with PyCharm by entering a command.
Click Terminal near PyCharm's ** Python Console **
The following parts, You can install the library ** XXXX ** by typing the following command from.
(venv) C:\Users\***\Desktop\python>pip install XXXX
In the above, I introduced how to install an external library by command. There is another way to install it in PyCharm, so I will explain how to do it. From now on, I will use this method. Let's actually install a package for data analysis called ** pandas **.
Select [File] → [Settings].
Here you will find the currently installed packages. Press the ** "+" ** button on the right side.
Search for the package name you want to install. This time, enter "pandas" in the red frame below and it will be searched, so click it and click ** "Install Package" ** of the button below.
When the installation is completed, the following red frame will be displayed, so close it with ×.
Make sure "Pandas" is installed. As mentioned above, packages such as "numpy" are also installed, but you can see that they are installed together because they depend on Pandas.
Earlier, I installed using the example of pandas. Now let's install ** matplotlib **. Please refer to the previous procedure for the procedure.
The external library used this time uses this ** matplotlib ** package. matplotlib is a library for graphing and visualizing data used in the field of AI. Like numpy and pandas earlier, this is also very often used in the field of AI.
Let's actually create a program. Create a file with the file name samp08-04-01.py </ font> in chap08 </ font>, and the following code Please write. The program described this time will draw a graph showing the change in weight.
.samp08-04-01.py
import matplotlib.pyplot as plt
data = [79.2, 79.1, 78.7, 79.4, 78.2, 78.5, 78.1, 78.3, 78.0, 77.4, 77.1, 76.9, 76.5, 76.3, 75.2]
plt.plot(data)
plt.title('Change in weight')
plt.show()
[Execution result] </ font>
This time, since matplotlib is used, it is output in graph format instead of output on the console screen.
First, ** import ** imports a module called ** pyplot ** in a package called ** matplotlib **. The name is now aliased as ** plt **.
The weight data ** data ** in list format is drawn by ** plt.plot (data) **, and the title of the graph is "Change in weight". Finally, ** plt.show () ** displays the graph. (If there is no show function, the graph will not be displayed.)
Note that matplotlib has more detailed functions and modules, so please check it out. Please refer to the AI-related books for details on matplotlib.
This time, I installed numpy, pandas, and matplotlib, and tried to draw a graph using the example of matplotlib. There are various functions and modules in this package as well, and we will create them while examining them. As I mentioned somewhere before, the programs I write in practice are researched. This time, let's check the library called matplotlib and execute various processes.