Section 1. Chapter 3
single
Counting Categorical Data
Swipe to show menu
A countplot is a plot that takes a categorical list and returns columns that represent the number of list entries for each category.
12345678910111213# Importing the `seaborn` library import seaborn as sns # Importing `matplotlib.pyplot` import matplotlib.pyplot as plt # Data list data_list = ['apple', 'milk', 'milk', 'milk', 'apple', 'milk', 'milk', 'milk', 'fish'] # Creating the countplot sns.countplot(x=data_list, palette='mako') # Showing the plot plt.show()
To initialize a countplot, you need to input at least 1 parameter: x (the column in which values will be counted).
Note
You may also use y instead of x to change the orientation of the plot.
As seaborn is based on matplotlib, you may use a special matplotlib.pyplot library and its function plt.show() to show the plot.
Task
Swipe to start coding
- Import the
seabornlibrary with thesnsalias; - Import the
matplotlib.pyplotlibrary with thepltalias; - Initialize the x-oriented countplot for
guests_list; - Show the plot.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 3
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat