A Python script that parses multi-line text reports with inconsistent formatting and extracts structured data (company name, address, phone, contact, city/state/zip, permits, expiration dates).
Demonstrates ability to:
- Extract data from unstructured text
- Handle irregular formatting (inconsistent spacing, page headers, line breaks)
- Convert messy reports into clean CSV for analysis
- Apply pattern matching and edge case handling
The script:
- Reads a text file (exported from PDF or other source)
- Identifies line patterns based on indentation and content
- Splits fields using multi-space delimiters
- Handles edge cases like missing data or varying field order
- Outputs a structured CSV file
- Regex pattern matching (
re.split(r' {2,}', line)) - Line-by-line state tracking
- Indentation-based parsing (space detection)
- Date pattern detection
parser.py— Main extraction scriptsample_input.txt— Example of the expected text format (synthetic data)sample_output.csv— Example of the structured output
Company Name 123 Main St, City (555) 123-4567
Contact Person City, State 12345 PERMIT123 04/15/2026
| Company Name | Address | Phone | Contact | City/State/Zip | Permits | Exp Date |
|---|---|---|---|---|---|---|
| Example Co | 123 Main St | (555) 123-4567 | Contact Person | City, State 12345 | PERMIT123 | 04/15/2026 |
python parser.py- Assumes consistent delimiter (2+ spaces)
- Requires text extraction from PDF before parsing
- Designed for specific report structure
This script was developed for a real-world data extraction task. The original data cannot be shared due to privacy and ethical considerations. The methodology is demonstrated using synthetic data.