Before any model exists there is the part nobody puts in the demo reel: the data is wrong. This page generates 200 rows of realistic sales chaos, duplicates, missing values, sentinel codes like -999, and casing that turns one city into four, then cleans it step by step and explains why each step comes in that order. This is the unglamorous floor of the Machine Learning layer, and it is where most real projects spend their time.
browser version uses hand-written array passes in place of pandas — same operations (dropna, fillna, drop_duplicates, groupby, resample), smaller engine. The chart is drawn on a raw canvas rather than matplotlib.
A seeded pseudo-random generator (mulberry32) builds 200 sales rows and then deliberately damages them, so every run of this page produces the identical mess and the cleaning is reproducible. The pipeline runs in a specific order for a specific reason: sentinel values like −999 and the string "N/A" are converted to real nulls first, because otherwise the imputation step would happily average a −999 into your mean. Text fields are stripped and case-folded before anything compares them, because " tokyo" and "Tokyo" are the same city only after normalisation. Deduplication then runs on the business key (order id) rather than on whole rows, since a duplicate with one drifted field is still a duplicate. Only at the end are numeric gaps filled and revenue recomputed from quantity times price, so aggregation sees one clean version of each fact.