0
0
Data Analysis Pythondata~10 mins

Categorical plots (boxplot, violinplot) in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a boxplot using seaborn.

Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')
sns.boxplot(x='day', y='total_bill', data=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Adata
Bsns
Cplt
Dtips
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the seaborn module instead of the dataset.
Passing the plotting module plt instead of the dataset.
Using the dataset name 'tips' as a string instead of the variable.
2fill in blank
medium

Complete the code to create a violinplot grouped by 'sex'.

Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')
sns.violinplot(x='day', y='total_bill', hue=[1], data=data)
plt.show()
Drag options to blanks, or click blank then click option'
A'smoker'
B'sex'
C'time'
D'size'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'time' or 'smoker' instead of 'sex' for grouping.
Not passing the column name as a string.
3fill in blank
hard

Fix the error in the code to plot a boxplot with seaborn.

Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')
sns.boxplot(x='day', y='total_bill', data=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Aplt
Bsns
Ctips
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string 'tips' instead of the variable.
Passing the seaborn or matplotlib modules instead of the dataset.
4fill in blank
hard

Fill both blanks to create a violinplot with split by smoker status.

Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')
sns.violinplot(x=[1], y='total_bill', hue=[2], data=data, split=True)
plt.show()
Drag options to blanks, or click blank then click option'
A'day'
B'sex'
C'smoker'
D'time'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the x and hue parameters.
Using 'sex' or 'time' instead of 'smoker' for hue.
5fill in blank
hard

Fill all three blanks to create a boxplot grouped by day and colored by time.

Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')
sns.boxplot(x=[1], y=[2], hue=[3], data=data)
plt.show()
Drag options to blanks, or click blank then click option'
A'day'
B'total_bill'
C'time'
D'sex'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x and y parameters.
Using 'sex' instead of 'time' for hue.
Not passing column names as strings.