All courses
PythonIntermediate
Working with Data in Python
Clean, read, count and report on everyday data using only the Python standard library: text, CSV, JSON, dates and tidy text reports.
Recommended first: Intermediate Python. This course builds on it.
Free to browse. You sign in at the first lesson so your progress is saved.
What you will be able to do
- Clean messy text with string methods and simple regular expressions
- Read and write CSV and JSON with the csv and json modules
- Count, group, sort and average records with collections and statistics
- Parse, format and compare dates with datetime and timedelta
- Turn raw CSV text into a neatly aligned spending report
Syllabus
6 modules and 21 lessons. Each lesson is a short read followed by an exercise with tests.
Module 1Cleaning text
Tidy messy text with string methods and simple regular expressions.4 lessons, about 49 min
- 1Trimming spaces and fixing caseRemove stray whitespace and make capital letters consistent.10 min
- 2Splitting and joining textBreak a line of text into a list, then glue a list back into text.12 min
- 3Replacing and testing textSwap out characters and check what a string starts with or contains.12 min
- 4Finding patterns with reUse regular expressions to pull out and tidy text that follows a pattern.15 min
Module 2Reading and writing CSV
Read rows from CSV text, handle quoted fields and write CSV of your own.4 lessons, about 52 min
- 5Reading CSV rowsUse csv.reader and io.StringIO to loop over the rows of a CSV.12 min
- 6Rows as dictionariesUse csv.DictReader to look up values by column name.12 min
- 7Quoted fields and missing valuesHandle commas inside values and blank cells without crashing.14 min
- 8Writing CSV textProduce CSV with csv.writer and csv.DictWriter.14 min
Module 3Working with JSON
Read nested JSON, write it back out neatly and cope with bad input.3 lessons, about 38 min
Module 4Counting and grouping
Count things, group records, sort them and summarise them with averages.4 lessons, about 52 min
- 12Counting with CounterTally how often each value appears and find the most common.12 min
- 13Grouping with defaultdictCollect records into groups by a shared value.14 min
- 14Sorting records by a keySort dictionaries by any field, in either direction, with tie-breaks.14 min
- 15Averages with statisticsSummarise numbers with mean, median and friends.12 min