0
0
Pandasdata~10 mins

Box plots in Pandas - 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 box plot of the 'age' column using pandas.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'age': [23, 45, 31, 35, 22, 40, 29, 50]}
df = pd.DataFrame(data)
df.boxplot(column=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Aage
B'age'
C'Age'
Ddf['age']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the column variable without quotes causes an error.
Passing the entire series instead of the column name.
2fill in blank
medium

Complete the code to create a box plot for the 'score' column with a grid.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'score': [88, 92, 79, 93, 85, 90, 87, 95]}
df = pd.DataFrame(data)
df.boxplot(column=[1], grid=True)
plt.show()
Drag options to blanks, or click blank then click option'
A'score'
Bscore
C'Score'
Ddf['score']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column name without quotes.
Using the wrong case for the column name.
3fill in blank
hard

Fix the error in the code to plot a box plot for the 'height' column.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'height': [160, 170, 165, 180, 175, 168, 172, 169]}
df = pd.DataFrame(data)
df.boxplot(column=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'height'
Bheight
Cdf['height']
D'Height'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column variable without quotes.
Using the wrong case for the column name.
4fill in blank
hard

Fill both blanks to create a box plot for the 'weight' column and set the color to 'green'.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'weight': [70, 80, 75, 85, 90, 78, 82, 77]}
df = pd.DataFrame(data)
df.boxplot(column=[1], color=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'weight'
B'blue'
C'green'
D'Weight'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong case for column name.
Passing color without quotes.
5fill in blank
hard

Fill all three blanks to create a box plot for the 'salary' column, set the grid to True, and change the box color to 'red'.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'salary': [50000, 60000, 55000, 65000, 70000, 62000, 58000, 63000]}
df = pd.DataFrame(data)
df.boxplot(column=[1], grid=[2], color=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A'Salary'
BTrue
C'red'
D'salary'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong case for column name.
Passing grid as a string instead of boolean.
Forgetting quotes around color.