#137 Python for data 6.3 min
Polars for pandas Users: One Report, Translated
One made-up report in pandas and Polars: same 4 rows, South at 6,814.5 in both.
Predict a missed target
Copy the code folder first. Before running anything, look at the report in the video: South made 6,814.5 against a target of 6500. In data.py change South's target from 6500 to 7000. Predict which columns in the South row change and which stay the same. Then run python run.py and check your prediction. This needs pandas and Polars as in the video's requirements.
A hint
The revenue and orders columns come from the orders, not from the targets.
Remove the coupon gaps
In data.py change rng.choice([5, 10, None]) to rng.choice([5, 10]) so no order lacks a coupon. Predict the two coupon dtype lines that run.py prints, given what the video said about whole numbers with gaps. Then run python run.py and compare. Does the report change?
A hint
The random choice now draws from two values, so the other made-up columns can change as well.
Change the size filter
In both pandas_way.py and polars_way.py change the quantity filter from 5 to 8. Predict whether each region's order count goes up or down, and whether pandas and Polars still agree. Run python run.py to check.
A hint
Change both files, or the agree line will show False for a reason that has nothing to do with Polars.
Sort before the join
In polars_way.py remove the .sort('region') line at the end and add .sort('region') right after the .agg(...) line, before the join. The video says an earlier draft like this made the lazy result come back in a different order. Predict what the two 'agree' lines will print, run python run.py, and say what you saw. The video also warns that the order is not promised, so the result may differ on another machine.
A hint
Put the line back where it was afterwards.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
Made-up data of a thousand rows, five common steps only, and no timing, so it makes no speed or memory claim.
