Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge 2: Exploring Categorical Data | Seaborn
Data Science Interview Challenge

book
Challenge 2: Exploring Categorical Data

Visualizing categorical data is crucial for gaining insights into how different categories relate to other variables. Categorical data, unlike continuous data, falls into discrete categories or labels. Seaborn, with its suite of powerful tools, provides efficient ways to visualize and interpret such data.

Visualizing categorical variables with Seaborn allows you to:

  • Compare the distribution of a numerical variable across different categories.

  • Visualize the relationships between two categorical variables.

  • Highlight how categorical variables relate to one or more numerical variables.

By leveraging Seaborn's functionalities, one can dive deep into the intricacies of categorical data, enabling a holistic understanding of its nuances.

Task

Swipe to start coding

Using Seaborn, dive into the world of categorical data visualization:

  1. Create a box plot to display the distribution of a numerical variable across different categories.
  2. Display the distribution of a numerical variable across different categories using a swarm plot.
  3. Visualize the count of observations in each category using a count plot.

Solution

import seaborn as sns
import matplotlib.pyplot as plt

# Sample data
data = sns.load_dataset("tips")
days = data['day']
total_bill = data['total_bill']
time = data['time']

# 1. Creating a box plot
sns.boxplot(x=days, y=total_bill)
plt.title('Box plot of Total Bill across Days')
plt.show()

# 2. Displaying distribution using a swarm plot
sns.swarmplot(x=days, y=total_bill)
plt.title('Swarm plot of Total Bill across Days')
plt.show()

# 3. Count of observations using a bar plot
sns.countplot(x=days)
plt.title('Bar plot of Days')
plt.show()

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 2
import seaborn as sns
import matplotlib.pyplot as plt

# Sample data
data = sns.load_dataset("tips")
days = data['day']
total_bill = data['total_bill']
time = data['time']

# 1. Creating a box plot
sns.___(___=days, y=total_bill)
plt.title('Box plot of Total Bill across Days')
plt.show()

# 2. Displaying distribution using a swarm plot
sns.___(x=days, ___=total_bill)
plt.title('Swarm plot of Total Bill across Days')
plt.show()

# 3. Count of observations using a bar plot
sns.___(___=days)
plt.title('Bar plot of Days')
plt.show()

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt