Understand the idea
An ECDF shows the fraction of observations at or below each x value. It uses the observed values without bins or smoothing.
A small example
For [2, 4, 4, 8], the ECDF at x=4 is 3/4 = 0.75. The fraction strictly above 4 is 1/4 = 0.25.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.ecdfplot(data=df, x="hours", ax=ax)
ax.set(title="Study club", xlabel="hours", ylabel="Proportion")
fig.tight_layout()
plt.show()What each part does
sns.ecdfplot- cumulative fraction from observations
x=- numeric column along the horizontal axis
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| student | club | hours | score | group |
|---|---|---|---|---|
| Ari | Art | 1 | 52 | A |
| Bo | Code | 3 | 71 | A |
| Cy | Art | 2 | 65 | B |
| Dee | Code | 4 | 82 | B |
| Eli | Art | 5 | 89 | A |
| Flo | Code | 3 | 76 | A |
| Gus | Art | 6 | 93 | B |
| Han | Code | 2 | 61 | B |
Your task · Follow
- Using df, call sns.ecdfplot for hours.
- Chart: title "Study club"; x "hours"; y "Proportion".
Hint
The ECDF height is the fraction at or below the horizontal value.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.ecdfplot(data=df, x="hours", ax=ax)
ax.set(title="Study club", xlabel="hours", ylabel="Proportion")
fig.tight_layout()
plt.show()