transform_column_case
Change text case in a CSV column to uppercase, lowercase, title case, or capitalize sentences for data standardization and analysis.
Instructions
Transform the case of text in a column.
Returns: ColumnOperationResult with transformation details
Examples: # Convert to uppercase transform_column_case(ctx, "code", "upper")
# Convert names to title case
transform_column_case(ctx, "name", "title")
# Convert to lowercase for comparison
transform_column_case(ctx, "email", "lower")
# Capitalize sentences
transform_column_case(ctx, "description", "capitalize")
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| column | Yes | Column name to transform text case in | |
| transform | Yes | Case transformation: upper, lower, title, or capitalize |
Implementation Reference
- The main asynchronous handler function that transforms the case of text in a specified DataFrame column based on the provided transform type (upper, lower, title, capitalize) using pandas string methods. It validates the column exists, applies the transformation in-place, counts changes, and returns a ColumnOperationResult.async def transform_column_case( ctx: Annotated[Context, Field(description="FastMCP context for session access")], column: Annotated[str, Field(description="Column name to transform text case in")], transform: Annotated[ Literal["upper", "lower", "title", "capitalize"], Field(description="Case transformation: upper, lower, title, or capitalize"), ], ) -> ColumnOperationResult: """Transform the case of text in a column. Returns: ColumnOperationResult with transformation details Examples: # Convert to uppercase transform_column_case(ctx, "code", "upper") # Convert names to title case transform_column_case(ctx, "name", "title") # Convert to lowercase for comparison transform_column_case(ctx, "email", "lower") # Capitalize sentences transform_column_case(ctx, "description", "capitalize") """ # Get session_id from FastMCP context session_id = ctx.session_id _session, df = get_session_data(session_id) _validate_column_exists(column, df) # Store original for comparison original_data = df[column].copy() # Apply case transformation str_col = df[column].astype(str) if transform == "upper": df[column] = str_col.str.upper() elif transform == "lower": df[column] = str_col.str.lower() elif transform == "title": df[column] = str_col.str.title() elif transform == "capitalize": df[column] = str_col.str.capitalize() else: msg = "transform" raise InvalidParameterError( msg, transform, "Supported transforms: upper, lower, title, capitalize", ) # Count changes made changes_made = _count_column_changes(original_data, df[column]) return ColumnOperationResult( operation=f"case_{transform}", rows_affected=changes_made, columns_affected=[column], )
- src/databeak/servers/column_text_server.py:534-534 (registration)Registration of the transform_column_case function as a tool named 'transform_column_case' on the FastMCP column_text_server instance.column_text_server.tool(name="transform_column_case")(transform_column_case)
- Pydantic-based input schema defined via Annotated types and Field descriptions for the tool parameters: ctx (Context), column (str), transform (Literal['upper', 'lower', 'title', 'capitalize']). Output is ColumnOperationResult.async def transform_column_case( ctx: Annotated[Context, Field(description="FastMCP context for session access")], column: Annotated[str, Field(description="Column name to transform text case in")], transform: Annotated[ Literal["upper", "lower", "title", "capitalize"], Field(description="Case transformation: upper, lower, title, or capitalize"), ], ) -> ColumnOperationResult:
- Helper function used by the handler to count the number of rows changed after transformation by comparing original and modified series.def _count_column_changes(original: pd.Series, modified: pd.Series) -> int: """Count number of changes between original and modified column data. Args: original: Original column data modified: Modified column data Returns: Number of rows that changed """ changed_mask = original.astype(str).fillna("") != modified.astype(str).fillna("") return int(changed_mask.sum())
- Helper function used by the handler to validate that the specified column exists in the DataFrame, raising ColumnNotFoundError if not.def _validate_column_exists(column: str, df: pd.DataFrame) -> None: """Validate that a column exists in the DataFrame. Args: column: Column name to check df: DataFrame to check in Raises: ColumnNotFoundError: If column doesn't exist """ if column not in df.columns: raise ColumnNotFoundError(column, df.columns.tolist())