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.
Contact Us