Visualize Data with pandas
The pandas library works in conjuction and is able to integrate other libraries very easily. One of those libraries is Matplotlib, which is a library used to visualize the data that you are working with.
Installation
pip install matplotlib
Importing
# best practice is to import matplotlib as mpl
import matplotlib as mpl# best practice is to import matplotlib.pyplot as plt
import matplotlib.pyplot as pltNote
Pyplot is a submodule of the matplotlib library for Python. Often times importing pyplot is enough and the need to import the entire matplotlib library is not necessary.
When importing matplotlib you are also importing pyplot as well. You could reference pyplot as such: mpl.pyplot.function_here()
Often times pyplot is used to generate 2-D graphics and since it is referenced often importing it separately and assigning it its own alias is helpful and may save some time!
Example
pyplotis imported asplt- Created a variable to hold the csv data
- Plot the data
- Show the data
| |
Note
When using tools like Jupyter Notebooks you may not need to include the plt.show() line of code shown in the above code block.
The plt.show() when used within a terminal emulator environment will create a separate pop-out of the graph. Tools like Jupyter Notebooks will include the visual within the notebook itself, eliminating the need for the pop out window.