LearnPy Hub
← Pandas: Cleaning & Preprocessing problems
Medium

Label Encode the Product

Turn the product column into numbers with df['product'].astype('category').cat.codes (categories in alphabetical order get 0, 1, 2, …). Print each category with its code as product code, then the codes of all rows on one line.

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
2026-02-18 Khulna Tea 450
2026-03-07 Sylhet Rice 800
2026-03-21 Dhaka Tea 650
END
Output
Rice 0
Tea 1
1 1 0 1 0 1

Sample 2

Input
2026-05-01 Dhaka Tea 100
END
Output
Tea 0
0
solution.py
Output appears here
Label Encode the Product · Python practice problem · LearnPy Hub