SigmaAnalytics & Tech
A14PythonBeginnerAbout 120 min to complete

File Handling

Reliable, portable, encoding-correct data input and output — the step that begins every real analysis.

Notebook

About 120 minutes to complete

Enrol to read the notebook and download it to run.

What this module covers

Reliable, portable, encoding-correct data input and output — the step that begins every real analysis.

By the end of it

  • Open files in the correct mode and explain what each mode does to existing data
  • Use the with statement, and articulate exactly what it guarantees
  • Handle encodings explicitly, including BOM-laden Excel exports
  • Build portable paths with pathlib that work on any operating system
  • Read and write CSV with the csv module, including DictReader/DictWriter
  • Serialise to and from JSON, handling types that JSON does not natively support
  • Discover files with glob and process folders in bulk
  • Stream through files too large to fit in memory