Build muscle memory with core Pandas methods. In this hands-on exercise, load the benchmark 35-row student dataset (student.xlsx), inspect dimensions and data types, slice records, filter by conditional thresholds, calculate summary statistics, and query unique categorical values.
The 35-row student benchmark dataset contains five columns: id, name, class, mark, and gender. You can download the workbook or copy the dictionary generator from the Sample Student DataFrame guide:
Download student.xlsx (35 Rows) ↓ View Dataset Guide →
download/student.xlsx into a DataFrame using id as the index.shape) and total row count.head().name column.mark column using sort_values().class column and count total unique classes (nunique()).mark > 60.'Three' with marks greater than 50 using combined boolean criteria.import pandas as pd
# 1. Read Excel file
df = pd.read_excel("download/student.xlsx", index_col="id")
# 2. Dimensions & Row Count
print("Shape:", df.shape) # (35, 4)
print("Total Rows:", len(df))
assert df.shape[0] == 35
assert len(df) == 35
# 3. First 4 Rows
print("
First 4 Rows:
", df.head(4))
# 4. Column Names
print("
Columns:", df.columns.tolist())
# 5. First 5 Names
print("
First 5 Names:
", df["name"].head(5))
# 6. Top 5 Marks
top5_marks = df.sort_values(by="mark", ascending=False).head(5)
print("
Top 5 Highest Marks:
", top5_marks)
assert top5_marks.iloc[0]["name"] == "Kenn Rein"
assert top5_marks.iloc[0]["mark"] == 96
# 7. Unique Classes
classes = df["class"].unique()
print("
Unique Classes:", classes)
print("Class Count:", df["class"].nunique())
assert df["class"].nunique() == 7
# 8. Mark > 60 Filter
high_scorers = df[df["mark"] > 60]
print(f"
Students with Mark > 60: {len(high_scorers)}")
assert len(high_scorers) > 0
# 9. Multiple Conditions: Class Three and Mark > 50
class3_passed = df[(df["class"] == "Three") & (df["mark"] > 50)]
print(f"Class Three with Mark > 50: {len(class3_passed)}")
# 10. Summary Metrics
print(f"Average Mark: {df['mark'].mean():.2f}")
print(f"Highest Mark: {df['mark'].max()}")
print(f"Total Mark Sum: {df['mark'].sum()}")
assert df["mark"].max() == 96
Open in Google Colab View on GitHub
Run all 10 student dataset query solutions interactively in Google Colab. The 35-row benchmark dataset is directly embedded.
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.
14-07-2021 | |
| You are doing amazing job. | |