add_column
Add new columns to dataframes with constant values, lists, or computed formulas for data transformation and analysis.
Instructions
Add a new column to the dataframe.
Returns: ColumnOperationResult with operation details
Examples: # Add column with constant value add_column(ctx, "status", "active")
# Add column with list of values
add_column(ctx, "scores", [85, 90, 78, 92, 88])
# Add computed column
add_column(ctx, "total", formula="price * quantity")
# Add column with complex formula
add_column(ctx, "full_name", formula="first_name + ' ' + last_name")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the new column to add | |
| value | No | Single value for all rows or list of values (one per row) | |
| formula | No | Safe mathematical expression to compute column values (e.g., 'col1 + col2') |
Input Schema (JSON Schema)
{
"properties": {
"formula": {
"anyOf": [
{
"$ref": "#/$defs/SecureExpression"
},
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Safe mathematical expression to compute column values (e.g., 'col1 + col2')"
},
"name": {
"description": "Name for the new column to add",
"type": "string"
},
"value": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
},
{
"type": "number"
},
{
"type": "boolean"
},
{
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
},
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "null"
}
]
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"description": "Single value for all rows or list of values (one per row)"
}
},
"required": [
"name"
],
"type": "object"
}