liveBook · Manning

Don't repeat yourself principle

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

Don't repeat yourself is a software design principle that avoids duplicating logic or equivalent code.

Don't Repeat Yourself avoids duplicating equivalent logic. When benchmarking several file formats, consolidate shared timing code in a loop instead of copying it for every method. section 12.6

A Python dictionary can map format names to dataframe-writing methods. Iterating over those key–value pairs keeps the workflow cleaner, easier to debug, and easier to extend. section 12.6

Benchmarking file formats

For a NYC parking-violations dataframe, one loop benchmarks JSON, CSV, and feather output. The recorded write times are about 46, 114, and 8 seconds respectively, while shared timing logic appears only once.

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Demonstrates replacing duplicated blocks with a method dictionary and loop, without developing broader design theory.
Examples
Benchmarks JSON, CSV, and feather writes for a NYC parking-violations dataframe.
What it assumes
Assumes Python knowledge beyond pandas, especially dictionaries, callable methods, loops, and timing functions.
What you can do after
Apply it via Python dictionaries and loops to consolidate repeated operations across related methods.
How it connects
Connects DRY with Python dictionaries, methods, loops, dataframe serialization, and performance benchmarking.

Also explained in

Compare how 10 books explain don't repeat yourself principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.