Ploting using Pandas
Table of contents
Introduction to plotting with Pandas
Data visualization is a powerful tool for gaining insights from data and effectively communicating your findings to others. When working with data in Python, Pandas, a popular data manipulation library, provides an easy and efficient way to create a wide range of plots and charts.
In this section, we will explore how Pandas can be used for data visualization, allowing you to generate informative and visually appealing plots directly from your DataFrame. Whether you’re analyzing trends, exploring patterns, or presenting your results, Pandas’ integration with Matplotlib, a popular plotting library, makes it a valuable tool for data visualization.
Throughout this section, we’ll delve into various types of plots, such as line plots, bar plots, scatter plots, histograms, and more. We’ll demonstrate how to customize and style your plots, add labels and titles, and incorporate them into your data analysis workflow. By the end, you’ll have a solid foundation for using Pandas to create meaningful visualizations that enhance your data-driven decision-making processes.
Matplotlib
It’s really easy to plot any data with Pandas just add ‘.plot()’ to any Dataframe or Series.
To have the full functionalities is better to import matplotlib
as well using
import matplotlib.pyplot as plt
For example let’s plot our powerbycanton
serie :
powerbycanton.plot()
This kind of graph will be better with a bar plot :
powerbycanton.plot(kind = 'bar')
It can be interesting to specify a title, axis label, and also to sort the values in an non-ascending order :
powerbycanton.sort_values(ascending=False).plot(kind = 'bar',title = "Total Power of electrical plant by Swiss Canton",xlabel="Canton",ylabel="Power (kW)")
You can save the graphic by using :
plt.savefig('my_plot_powercanton.png', format='png')
To know more about plotting you can have a look at the Pandas Documentation.