pandas in practice

Reading and writing files correctly, method chains and fast vectorised code, and a complete analysis from question to report.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    Reading and writing files Intermediate

    Getting data in and out of pandas: read_csv with separators, missing-value markers, column selection, types, dates and chunks; writing with to_csv and its quoting rules; and the other formats pandas reads and writes.

  2. 2

    Method chaining, apply and performance Advanced

    Writing clear, fast pandas: method chains with assign, query and pipe, when apply with axis=1 is acceptable and how to replace it with vectorised code, np.where and np.select, and avoiding the SettingWithCopyWarning.

  3. 3

    A complete analysis with pandas Advanced

    One analysis from start to finish: framing the question, loading and inspecting, cleaning, merging, grouping, ranking with nlargest, computing shares and per-customer summaries, checking the numbers and presenting the result.

Module practice

Module quiz

1. Which read_csv argument sets the field separator?
2. What does df.assign(total=...) return?
3. What does nlargest(3, 'x') return?
4. Why write to_csv(..., index=False)?
5. Which replaces a slow apply(axis=1) for a two-way rule?
6. Revenue per category adds up to more than total sales. What should you check first?

‹ Combining tables, text and datesFinal assessment ›