Creating bar plots

Bar graphs are most used to compare between different groups or to track changes over time. Using bar plots to the crosstab is one of the efficient ways to conclude the crosstab and analyze them even better.

Syntax: DataFrame.plot.bar(x=None, y=None, **kwargs)

Code:

Python3




# importing the pandas library
import pandas as pd
 
# Reading the csv file and storing it in a variable
df = pd.read_csv('Data.csv')
 
# Creating crosstab
crosstb = pd.crosstab(df.Nationality, df.Handedness)
 
# Creating barplot
barplot = crosstb.plot.bar(rot=0)


Output:

Using pandas crosstab to create a bar plot

In this article, we will discuss how to create a bar plot by using pandas crosstab in Python. First Lets us know more about the crosstab, It is a simple cross-tabulation of two or more variables.

Similar Reads

What is cross-tabulation?

It is a simple cross-tabulation that help us to understand the relationship between two or more variable. It will give a clear understanding of the data and makes analysis easier....

Crosstab using pandas

Before creating the barplot we should create cross-tabulation using pandas....

Creating bar plots

...

Stacked barplot

Bar graphs are most used to compare between different groups or to track changes over time. Using bar plots to the crosstab is one of the efficient ways to conclude the crosstab and analyze them even better....

Creating bar plot using more than two variables from the crosstab

...

Contact Us