remove_columns
Remove specified columns from CSV dataframes to clean datasets, reduce file size, and focus on relevant information.
Instructions
Remove columns from the dataframe.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| columns | Yes |
Implementation Reference
- Core handler implementation that validates columns, drops them from the pandas DataFrame using df.drop(), records the operation, and returns success info with remaining columns.async def remove_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """ Remove columns from the dataframe. Args: session_id: Session identifier columns: List of column names to remove ctx: FastMCP context Returns: Dict with success status and removed columns """ try: manager = get_session_manager() session = manager.get_session(session_id) if not session or session.df is None: return {"success": False, "error": "Invalid session or no data loaded"} df = session.df # Validate columns exist missing_cols = [col for col in columns if col not in df.columns] if missing_cols: return {"success": False, "error": f"Columns not found: {missing_cols}"} session.df = df.drop(columns=columns) session.record_operation(OperationType.REMOVE_COLUMN, { "columns": columns }) return { "success": True, "removed_columns": columns, "remaining_columns": session.df.columns.tolist() } except Exception as e: logger.error(f"Error removing columns: {str(e)}") return {"success": False, "error": str(e)}
- src/csv_editor/server.py:249-256 (registration)MCP tool registration via @mcp.tool decorator. Thin wrapper that forwards to the core implementation in transformations.py.@mcp.tool async def remove_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """Remove columns from the dataframe.""" return await _remove_columns(session_id, columns, ctx)
- src/csv_editor/server.py:249-256 (handler)Entry-point handler registered with FastMCP, defining input schema via type hints and docstring, delegates to internal _remove_columns.@mcp.tool async def remove_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """Remove columns from the dataframe.""" return await _remove_columns(session_id, columns, ctx)