🐍 Python for Everyone

← Back to exercises

Chapter 24 Practice Bank 70-90 min, hands-on

Practice Bank: Pandas for Data Analysis

A deeper set of practice problems, organized by topic, for extra reps beyond the main exercises — including scenario-based problems written in the same style you'll meet in real interviews. Every task here uses real pandas directly. No import beyond pandas/numpy/io/json/os/re/math/datetime/random/csv/threading/concurrent.futures.

How to run these Download starter.py below and run python3 starter.py from inside the same folder. Install pandas first if you haven't: pip install pandas.

Topic 1: What Pandas Is & Why It Exists

1 Build a Series

Find # TODO 1.1. Write make_series(values).

2 Build a labeled table

Find # TODO 1.2. Write make_labeled_table(names, scores).

3 Debug the Code

Find # TODO 1.3. This wrongly claims DataFrames are unrelated to NumPy. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 1.A. Write should_use_dataframe(has_mixed_types, needs_column_labels).

💼 Interview Prep

Why pandas stays fast

Find # TODO 1.B. Write explain_why_pandas_is_built_on_numpy().

Topic 2: Creating a DataFrame

1 From a dict

Find # TODO 2.1. Write df_from_dict(data_dict).

2 From CSV-format text

Find # TODO 2.2. Write df_from_csv_text(csv_text).

3 Debug the Code

Find # TODO 2.3. This passes a raw string to read_csv() instead of wrapping it in StringIO. Fix it.

💼 Scenario

Reading a Real Export

Find # TODO 2.A. Write build_report_df(products, regions, revenues).

💼 Interview Prep

read_csv() vs. the csv module

Find # TODO 2.B. Write explain_read_csv_vs_csv_module().

Topic 3: Inspecting Data

1 Row and column count

Find # TODO 3.1. Write row_and_column_count(df).

2 Column names

Find # TODO 3.2. Write column_names(df).

3 Debug the Code

Find # TODO 3.3. This calls .info() where .describe() was needed. Fix it.

💼 Scenario

Sanity-Checking a New Dataset

Find # TODO 3.A. Write quick_health_check(df).

💼 Interview Prep

.info() vs. .describe()

Find # TODO 3.B. Write explain_info_vs_describe().

Topic 4: Selecting, Filtering & .loc[] vs. .iloc[]

1 Select a column

Find # TODO 4.1. Write select_column(df, col_name).

2 Filter above a threshold

Find # TODO 4.2. Write filter_above(df, col_name, threshold).

3 Debug the Code

Find # TODO 4.3. This uses .loc[] where .iloc[] was needed. Fix it.

💼 Scenario

Flagging Low Stock

Find # TODO 4.A. Write flag_low_stock(df, threshold=10).

💼 Interview Prep

.loc[] vs. .iloc[]

Find # TODO 4.B. Write explain_loc_vs_iloc().

Topic 5: Adding Columns & Handling Missing Data

1 Add a computed column

Find # TODO 5.1. Write add_computed_column(df, new_col, col_a, col_b).

2 Fill missing values

Find # TODO 5.2. Write fill_missing(df, col_name, fill_value).

3 Debug the Code

Find # TODO 5.3. This only checks one column for missing values instead of the whole DataFrame. Fix it.

💼 Scenario

Cleaning a Messy Export

Find # TODO 5.A. Write clean_export(df).

💼 Interview Prep

.isna(), .dropna(), .fillna()

Find # TODO 5.B. Write explain_missing_data_tools().

Topic 6: Grouping, Aggregation & Sorting

1 Total per group

Find # TODO 6.1. Write total_per_group(df, group_col, value_col).

2 Sort descending

Find # TODO 6.2. Write sorted_descending(df, col_name).

3 Debug the Code

Find # TODO 6.3. This sorts ascending where a "top 2" report needed descending. Fix it.

💼 Scenario

Regional Sales Report

Find # TODO 6.A. Write regional_sales_report(df).

💼 Interview Prep

The groupby "top N" pipeline

Find # TODO 6.B. Write explain_groupby_pipeline().

Checking your work Compare your output against solution.py. Your exact wording doesn't need to match on the explanation-style tasks — the goal is that your program runs without errors and does what each TODO asks. Every numeric task's output is exactly reproducible.
← Exercises Challenges →