In This Article, You Will Learn About Python Pandas DataFrame Operation.
Python Pandas Plotting – Before moving ahead, let’s know about Python Pandas Correlations
Table of Contents
Pandas Plotting
To create diagrams such as Histogram, Pie-Chart, Bar graph, etc., in Python, Pandas take help from Python Matplotlib library and use its plot() method.
Note: You will learn later in detail about Python Matplotlib Library.
Example – Plotting Pandas Data set in a graph by importing Matplotlib.
import pandas as pd
import matplotlib.pyplot as plt
file = pd.read_csv('file.csv')
file.plot()
plt.show()
As a result, it returned a graph of dataset of Pandas.
Click to Open File
Click to Download File
Scatter Plot
A Scatter Plot needs to have an x-axis and a y-axis.
The plot has the argument “kind = scatter” to specify Scatter Plot.
Example – Plotting a Scatter graph of Pandas data set.
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('data.csv')
data.plot(kind = 'scatter', x = 'Dur.', y = 'Cal')
plt.show()
As can be seen, it returned a Scatter (graph) of dataset of Pandas.
Example – Plotting a Scatter graph of dataset of Pandas.
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('data.csv')
data.plot(kind='scatter', x='Dur.', y='X')
plt.show()
As a result, it returned a Scatter (graph) of dataset of Pandas.
Histogram
A Histogram needs to have only one column.
The plot argues “kind = hist” to specify a histogram.
A histogram shows the frequency of a given value, e.g., how many quantities of product are sold from Jan to Oct.
Example – Plotting data set into Histogram.
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('data.csv')
data["Dur."].plot(kind='hist')
plt.show()
As shown above, it returned a Histogram (graph) of dataset of Pandas.
If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.