Solidify your data visualization skills with hands-on practice problems. This exercise hub tests your ability to select the right chart format, transform data with value_counts() and groupby(), customize dimensions and labels, and render clean charts across all Pandas plot types.
You can download the practice Excel file Download student.xlsx ↓ or generate the sample DataFrame directly in Python using the code below:
import pandas as pd
data = {
"id": range(1, 11),
"name": ["John", "Ravi", "Sara", "Alex", "Nina", "Mike", "Tara", "Leo", "Maya", "Omar"],
"class1": ["Four", "Three", "Four", "Five", "Three", "Four", "Five", "Three", "Four", "Five"],
"mark": [75, 82, 90, 65, 88, 70, 95, 60, 85, 78]
}
df = pd.DataFrame(data)
print(df)
Solve each of the following 5 core plotting challenges:
value_counts() and render an ordered line chart.class1 and plot the mean mark for each class.class1 and compute both the mean and maximum marks side-by-side.autopct).plot.density()).Click below to reveal verified Python code solutions for each exercise:
counts = df["class1"].value_counts().sort_index()
counts.plot.line(marker="o", grid=True, title="Class Student Enrollment Counts")
plt.ylabel("Student Count")
plt.show()
mean_df = df.groupby("class1")["mark"].mean()
mean_df.plot.bar(title="Mean Mark by Class", color="#2b5c8f")
plt.ylabel("Average Score")
plt.show()
agg_df = df.groupby("class1")["mark"].agg(["mean", "max"])
agg_df.plot.bar(title="Mean vs Maximum Mark by Class", figsize=(6.5, 4))
plt.ylabel("Marks")
plt.show()
counts = df["class1"].value_counts()
counts.plot.pie(autopct="%1.0f%%", title="Class Student Share")
plt.ylabel("")
plt.show()
df["mark"].plot.density(title="Student Mark Probability Density", bw_method=0.3)
plt.xlabel("Marks")
plt.show()
Explore dedicated tutorials for each individual chart format in this cluster:
| Tutorial | Method | Primary Analytical Purpose |
|---|---|---|
| Line Charts | df.plot.line() | Continuous series, time-series trends, and progression over ordered intervals. |
| Bar Charts | df.plot.bar() | Comparing discrete category metrics and multi-column grouped totals. |
| Horizontal Bars | df.plot.barh() | Leaderboards, rankings, and categories with long descriptive text labels. |
| Histograms | df.plot.hist() | Frequency counts across continuous data intervals with custom binning. |
| Box Plots | df.plot.box() | Five-number statistical summary (IQR, median) and outlier flier detection. |
| Pie Charts | df.plot.pie() | Relative percentage shares and composition of categorical totals. |
| Density Plots | df.plot.density() | Smooth Kernel Density Estimation (KDE) curves for continuous distributions. |
| Area Plots | df.plot.area() | Cumulative volume trends and stacked proportional accumulation over time. |
| Scatter Plots | df.plot.scatter() | Bivariate correlations, point dispersion, and 3D bubble chart sizing. |
| Hexbin Plots | df.plot.hexbin() | 2D hexagonal density binning for large datasets solving overplotting. |
| Plots from MySQL | pd.read_sql() | Extracting database records directly into analytical Pandas visualizations. |
Work through all exercises with pre-populated datasets and verified assertions in Google Colab:
Open in Google Colab View on GitHub
Work through all plotting practice challenges interactively, test your data transformation solutions, and verify your code against automated assertions directly in Google Colab. All sample datasets are embedded directly in the notebook.
Reference: Pandas DataFrame.plot official documentation.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.