Standardize Text Case Practice Problem
This data science coding problem helps you practice Text Data Cleaning, standardize text case, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Text Data Cleaning.
- Problem ID: 170
- Problem key: 170-standardize-text-case
- URL: https://datacrack.app/solve/170-standardize-text-case
- Difficulty: easy
- Topic: Text Data Cleaning
- Module: Data Cleaning
Problem Statement
# Standardize Text Case
### 🎯 Goal
Inconsistent casing — like `"JOHN DOE"`, `"jane smith"`, and `"Bob Jones"` — makes text comparison unreliable and grouping impossible. Standardizing case ensures uniform representation so that `"John"` and `"john"` are treated as the same entity.
### 💻 Task
Implement `standardize_case(data, column, case='lower')` that:
1. Converts the input dictionary to a DataFrame
2. Converts all text in the specified column to the target case: `'lower'`, `'upper'`, or `'title'`
3. Returns the transformed DataFrame as a dictionary
---
### 📥 Input
- `data`: A dictionary where keys are column names and values are lists of strings
- `column`: The name of the column to transform
- `case`: Target case — `'lower'`, `'upper'`, or `'title'` (default: `'lower'`)
### 📤 Output
- A dictionary representing the transformed DataFrame
---
### 🧩 Starter Code
```python
import pandas as pd
def standardize_case(data, column, case='lower'):
"""
Convert text column to a standardized case.
Args:
data (dict): Input data as dictionary
column (str): Column name to transform
case (str): Target case — 'lower', 'upper', or 'title'
Returns:
dict: Transformed DataFrame as dictionary
"""
# TODO: Convert input dictionary to DataFrame
# TODO: Apply the appropriate string method based on case parameter
# TODO: Return transformed DataFrame as dictionary
pass
```
---
### 💡 Examples
**Example 1:** Lowercase
```python
data = {"name": ["JOHN DOE", "jane smith", "Bob Jones"]}
standardize_case(data, "name", case="lower")
```
```
{'name': ['john doe', 'jane smith', 'bob jones']}
```
**Example 2:** Uppercase
```python
data = {"name": ["john doe", "JANE SMITH", "Bob Jones"]}
standardize_case(data, "name", case="upper")
```
```
{'name': ['JOHN DOE', 'JANE SMITH', 'BOB JONES']}
```
**Example 3:** Title case
```python
data = {"name": ["JOHN DOE", "jane smith", "bOB jONES"]}
standardize_case(data, "name", case="title")
```
```
{'name': ['John Doe', 'Jane Smith', 'Bob Jones']}
```Starter Code
import pandas as pd
def standardize_case(data, column, case='lower'):
"""
Convert text column to a standardized case.
Args:
data (dict): Input data as dictionary
column (str): Column name to transform
case (str): Target case — 'lower', 'upper', or 'title'
Returns:
dict: Transformed DataFrame as dictionary
"""
# TODO: Convert input dictionary to DataFrame
# TODO: Apply the appropriate string method based on case parameter
# TODO: Return transformed DataFrame as dictionary
pass