LearnPy Hub
← Pandas: Cleaning & Preprocessing problems
Hard

Encode and Scale for a Model

Prepare the sales table for a model. One-hot encode region and product with pd.get_dummies(df, columns=['region', 'product'], dtype=int), drop the date column, and standardise amount to a z-score (x − mean) / std with std(ddof=0) (0 if std is 0). Print the column names on one line, then every row's values on its own line, with the scaled amount to 2 decimals first and the dummy columns after it.

Input

Lines 'date region product amount', then END.

Output

Lines.

Sample 1

Input
2026-01-15 Dhaka Tea 500
2026-01-20 Sylhet Tea 300
2026-02-03 Dhaka Rice 1200
END
Output
amount region_Dhaka region_Sylhet product_Rice product_Tea
-0.43 1 0 0 1
-0.95 0 1 0 1
1.38 1 0 1 0

Sample 2

Input
2026-05-01 Dhaka Tea 100
END
Output
amount region_Dhaka product_Tea
0.00 1 1
solution.py
Output appears here
Encode and Scale for a Model · Python practice problem · LearnPy Hub