Block 44: Text & Log File Parsing
Extract structured data from plain text and log files.
Concepts
- Reading text files line-by-line
- str.split(), str.strip(), str.startswith()
- Detecting patterns with 'in' operator
- Building a list of parsed records
Code Examples
See exercise below.
Exercise
Read a log file; count ERROR, WARNING, and INFO lines separately. Extract timestamps and messages from each line into a DataFrame.
Homework
Write a function parse_log(filepath) → DataFrame that generalizes this pattern. Wednesday