Pandasdrill

All 45 pandas exercises

Pandasdrill is pandas practice in your browser. Every exercise shows you a small, realistic table and a task. You write Python in the editor, run it on real pandas, see your result as a table, and get it checked on the spot and again on a second dataset, so code that only fits the sample fails. The exercises are listed here level by level. 5 are free without an account; Pro unlocks the rest.

Start practicing free

Level 1: Selecting and filtering

Columns, loc and iloc, boolean masks, isin, between, query, sorting, head and nlargest.

  1. Pick two columnsFree
  2. Filter with a boolean maskFree
  3. Rows and columns with locFree
  4. Position-based slicing with ilocFree
  5. Match a list of values with isinFree
  6. Ranges with betweenPro
  7. Readable filters with queryPro
  8. Sort by two columnsPro
  9. Top three earnersPro

Level 2: Cleaning

Missing values, astype, string methods like strip, contains and extract, duplicates, rename, replace and dates.

  1. Fill missing values in one columnPro
  2. Drop rows missing a key fieldPro
  3. Convert text to numbersPro
  4. Tidy up text with strip and lowerPro
  5. Search text with str.containsPro
  6. Pull numbers out of codesPro
  7. Remove duplicate recordsPro
  8. Rename columns and replace a placeholderPro
  9. Dates with to_datetime and dtPro

Level 3: Aggregating

groupby with sum, mean and count, named aggregations, value_counts, pivot_table and crosstab.

  1. Total by groupPro
  2. Group means as a flat tablePro
  3. Count rows per groupPro
  4. Named aggregationsPro
  5. Group by two keysPro
  6. Pivot table with a fill valuePro
  7. Counts with crosstabPro
  8. Shares with value_countsPro
  9. Several statistics at oncePro

Level 4: Combining and reshaping

Inner and left merges, keys with different names, concat, melt, pivot, stack and unstack.

  1. Inner merge on a shared keyPro
  2. Left merge keeps every orderPro
  3. Merge on differently named keysPro
  4. Stack two tables with concatPro
  5. Merge twice, then aggregatePro
  6. Wide to long with meltPro
  7. Long to wide with pivotPro
  8. Columns into rows with stackPro
  9. Index level into columns with unstackPro

Level 5: Analysis

Rolling averages, pct_change, cumsum, rank, shift, monthly resampling, cut and qcut, apply with a function.

  1. Rolling averagePro
  2. Month over month growthPro
  3. Running totalPro
  4. Rank with tiesPro
  5. Change from the previous periodPro
  6. Monthly totals with resamplePro
  7. Quartile bins with qcutPro
  8. Age bands with cutPro
  9. Classify with applyPro

Try the first five exercises free.

No sign-up needed for the first five. If it works for you, Pro unlocks all 45, and a free account saves your progress and your code across devices.

Start practicing free