replace_in_column
Replace text patterns in CSV columns using regex or literal strings to clean, transform, or standardize data values.
Instructions
Replace patterns in a column with replacement text.
Returns: ColumnOperationResult with replacement details
Examples: # Replace with regex replace_in_column(ctx, "name", r"Mr.", "Mister")
# Remove non-digits from phone numbers
replace_in_column(ctx, "phone", r"\D", "", regex=True)
# Simple string replacement
replace_in_column(ctx, "status", "N/A", "Unknown", regex=False)
# Replace multiple spaces with single space
replace_in_column(ctx, "description", r"\s+", " ")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| column | Yes | Column name to apply pattern replacement in | |
| pattern | Yes | Pattern to search for (regex or literal string) | |
| replacement | Yes | Replacement text to use for matches | |
| regex | Yes | Whether to treat pattern as regex (True) or literal string (False) |
Input Schema (JSON Schema)
{
"properties": {
"column": {
"description": "Column name to apply pattern replacement in",
"type": "string"
},
"pattern": {
"description": "Pattern to search for (regex or literal string)",
"type": "string"
},
"regex": {
"description": "Whether to treat pattern as regex (True) or literal string (False)",
"type": "boolean"
},
"replacement": {
"description": "Replacement text to use for matches",
"type": "string"
}
},
"required": [
"column",
"pattern",
"replacement",
"regex"
],
"type": "object"
}