Pandas is a library used for data analysis and data manipulation in Python. We can use different types of graphs and charts to visualize the results of our analysis in pandas.
We can use different plots to visualize the analysis. Some types of plots that can be used are:
Basic plots
Bar plots
Scatter plots
Area plots
df.plot(x ='%%Employer%%', y='%%Variable 2 %%', kind = '%% Type of plot %%')
In the syntax, we pass one column of data in the form of Employer
as first value to x
variable and Average Salary
as second value to y
variable. Then we'll pass the type of the plot, we want to plot, in the kind
variable.
Let's explore how to implement it in the steps below:
The first step is creating data for the analysis. For instance, consider the following table:
Employer | Average Salary |
Company A | 14000 |
Company B | 15000 |
Company C | 12000 |
In this step, we will pass the value of the column to the dataframes
.
import pandas as pdimport matplotlib.pyplot as pltdata = {'Employer': ['Company A','Company B','Company C'],'Average_Salary': [14000,15000,12000]}
Now, we pass the column names to plot the data to the x
and y
variables and define the type of plot in the kind
variable.
import pandas as pdimport matplotlib.pyplot as pltdata = {'Employer': ['Company A','Company B','Company C'],'Average_Salary': [14000,15000,12000]}dataframes = pd.DataFrame(data,columns=['Employer','Average_Salary'])dataframes.plot(x ='Employer', y='Average_Salary', kind = 'bar')plt.show()
Line 4–5: Define data frames to store data.
Line 8–9: Pass the data as columns to the x
and y
variables and pass the plot type as bar to the kind
variable.
Free Resources