Normalize Ingredient Names to Title Case
Problem
A recipe app imports ingredient lines from many messy sources into the `ingredient_lines` DataFrame, so the casing is inconsistent. Rewrite the `raw_line` column into title case: the first letter of every word becomes uppercase and every other letter becomes lowercase. Words are separated by single spaces, and all existing spaces must be preserved exactly. Return `entry_id`, `raw_line` (unchanged), and the cleaned value as a new column `tidy_line`.
Input data
Example rows — the live problem includes the full dataset.
| entry_id | raw_line |
|---|---|
| 1 | two cups of FLOUR |
| 2 | one TEASPOON sea salt |
| 3 | fresh basil AND ripe tomato |
| 4 | EXTRA virgin olive OIL |
Expected output
Your answer should return 4 rows with the columns entry_id, raw_line, tidy_line.
Starter code (Pandas (Python))
import pandas as pd
def normalize_ingredient_names(ingredient_lines) -> pd.DataFrame:
# Your code here
return ingredient_linesSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock