Skip to main content
Glama

strip_column

Remove whitespace or specific characters from column values in CSV data to clean and standardize text fields for analysis.

Instructions

Strip whitespace or specified characters from column values.

Returns: ColumnOperationResult with strip details

Examples: # Remove leading/trailing whitespace strip_column(ctx, "name")

# Remove specific characters
strip_column(ctx, "phone", "()")

# Clean currency values
strip_column(ctx, "price", "$,")

# Remove quotes
strip_column(ctx, "quoted_text", "'\"")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnYesColumn name to strip characters from
charsNoCharacters to strip (None for whitespace, string for specific chars)

Implementation Reference

  • The handler function that executes the strip_column tool logic: strips leading/trailing whitespace or specified characters from all values in the given column of the session's dataframe, using pandas str.strip(), and returns a ColumnOperationResult with details on changes made.
    async def strip_column(
        ctx: Annotated[Context, Field(description="FastMCP context for session access")],
        column: Annotated[str, Field(description="Column name to strip characters from")],
        chars: Annotated[
            str | None,
            Field(description="Characters to strip (None for whitespace, string for specific chars)"),
        ] = None,
    ) -> ColumnOperationResult:
        r"""Strip whitespace or specified characters from column values.
    
        Returns:
            ColumnOperationResult with strip details
    
        Examples:
            # Remove leading/trailing whitespace
            strip_column(ctx, "name")
    
            # Remove specific characters
            strip_column(ctx, "phone", "()")
    
            # Clean currency values
            strip_column(ctx, "price", "$,")
    
            # Remove quotes
            strip_column(ctx, "quoted_text", "'\"")
    
        """
        # 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 strip operation
        if chars is None:
            # Strip whitespace
            df[column] = df[column].astype(str).str.strip()
        else:
            # Strip specified characters
            df[column] = df[column].astype(str).str.strip(chars)
    
        # Count changes made
        changes_made = _count_column_changes(original_data, df[column])
    
        return ColumnOperationResult(
            operation=f"strip_{'whitespace' if chars is None else 'chars'}",
            rows_affected=changes_made,
            columns_affected=[column],
        )
  • Registers the strip_column handler as a tool named 'strip_column' on the FastMCP server instance 'column_text_server'.
    column_text_server.tool(name="strip_column")(strip_column)
  • Pydantic-style type annotations with Field descriptions define the input schema for the tool: ctx (Context), column (str), optional chars (str|None). Output is ColumnOperationResult.
    async def strip_column(
        ctx: Annotated[Context, Field(description="FastMCP context for session access")],
        column: Annotated[str, Field(description="Column name to strip characters from")],
        chars: Annotated[
            str | None,
            Field(description="Characters to strip (None for whitespace, string for specific chars)"),
        ] = None,
    ) -> ColumnOperationResult:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonpspri/databeak'

If you have feedback or need assistance with the MCP directory API, please join our Discord server