practicepython.in
python exercises
171 exercises

Tables with pandas

pandas is the library everybody learns by copying from somewhere, which is why so much pandas code works by accident. These exercises are the behaviours that decide whether a pipeline is correct: an assignment that lands on a copy and is thrown away, a merge that silently multiplies your rows, a groupby that drops the rows with a missing key, and arithmetic that aligns on the index rather than on position. The heaviest track to open — about 9 MB the first time, because pandas brings numpy with it — and cached from then on.

12 exercisesdifficulty 2–4~310 min in total
How the answers split, as a percentage value_counts, normalize for proportions ~20 min The update that quietly did nothingdebug chained assignment, copy versus view ~24 min Half the league scored nothingdebug Series arithmetic aligns on the index, NaN from a missing label ~24 min The region that vanished from the reportdebug groupby drops missing keys, dropna=False ~24 min The total came out as a sentencedebug object dtype is not a number, to_numeric with errors='coerce' ~26 min The latest status, out of an event log drop_duplicates with subset and keep, sort before you dedupe ~26 min One row per channel, and a cost per click groupby with named aggregations, reset_index turns keys back into a column ~26 min A row-by-row loop over a table whole-column arithmetic, np.where and Series.clip ~26 min The month we sold everything twicedebug many-to-many merges, validate= ~26 min The grid averaged what it should have addeddebug pivot_table defaults to mean, pivot raises where pivot_table averages ~30 min Every month, including the quiet ones to_datetime and the .dt accessor, grouping by a period ~30 min The best three in every region groupby().head() takes the first rows, not the best, sort by several keys with one call ~28 min