-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Third Edition
By :
Once the data is cleaned we can process the results. For our example, we will calculate the average sale price by both location and day, as well as the total sales by location and day in the data range. As our data is stored by location, this will be done in two steps. First, we'll create the files per location, and then by date, using the date on the location results.
We will use the JSON file from the previous recipe that receives and transforms logs in the following format:
[<Timestamp>] - SALE - PRODUCT: <product id> - PRICE: <price>
Each line will represent a sale log.
We will use the parse and pydantic modules. Install the modules by adding them to requirements.txt:
$ echo "parse==1.20.2" >> requirements.txt
$ echo "pydantic==2.12.5" >> requirements.txt
$ uv pip install -r requirements.txt
The GitHub repository contains some log files to process with the following structure:
sale_logs/
OH...