AnalystPath

Normalize Ingredient Names to Title Case

PandasHardSenior level~10 min

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.

ingredient_lines
entry_idraw_line
1two cups of FLOUR
2one TEASPOON sea salt
3fresh basil AND ripe tomato
4EXTRA 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_lines

Solve 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

Related Pandas questions