Overview
The Bulk Rename of Keys feature enables users to rename multiple columns dynamically using Python Operations in eZintegrations. While the built-in rename operation is suitable for individual fields, Python-based renaming provides a scalable approach for handling large datasets.
This method is particularly useful for applying consistent naming conventions, such as adding prefixes to multiple keys within an array of dictionaries.
When to Use
Use this approach when multiple columns must be renamed simultaneously using a common pattern.
- Adding prefixes or suffixes to multiple fields
- Standardizing column naming conventions
- Preparing datasets for downstream integrations
- Handling dynamic or variable schemas
- Improving data consistency across pipelines
How It Works
The Python script retrieves the dataset items from the integration response and iterates through each record.
For every key in each record, a prefix is prepended to generate a new column name. The original dataset is then updated with the renamed keys.
Python Code for Renaming Multiple Columns
The following script demonstrates how to prepend a prefix to all column names inside a dataset.
Responsedata = []
new_data = pycode_data
prefix = "billTo_"
# Extract items from the dataset response
items = new_data["bizdata_dataset_response"]["items"]
updated_items = []
# Iterate through the items and rename each column by adding the prefix
for item in items:
updated_item = {}
for key, value in item.items():
new_key = f'{prefix}{key}' # Add the prefix to each column name
updated_item[new_key] = value
updated_items.append(updated_item)
# Update the original dataset with the renamed columns
new_data["bizdata_dataset_response"]["items"] = updated_items
pycode_data = new_data
Key Parameters
The following parameters control the behavior of the bulk renaming process.
| Parameter | Description |
|---|---|
| prefix | Defines the text added before each column name (for example, billTo_). |
| items | Represents the dataset records located under bizdata_dataset_response. |
How to Use
Follow these steps to rename multiple keys using Python Operations.
- Configure the integration to return data in the bizdata_dataset_response format.
- Open the Python Operation editor.
- Paste the bulk renaming script.
- Modify the prefix value as required.
- Save and deploy the workflow.
- Test the operation with sample data.
Use Case Example
This method is useful when standardizing billing or customer-related datasets.
- Original Key: name
- Renamed Key: billTo_name
- Original Key: address
- Renamed Key: billTo_address
- Result: Consistent prefixed fields
Troubleshooting
- Ensure the bizdata_dataset_response and items keys exist in the input.
- Verify that items contains a list of dictionaries.
- Check for null or empty datasets.
- Confirm that pycode_data is correctly assigned.
- Review logs if renamed fields are missing.
Frequently Asked Questions
What is the purpose of bulk renaming?
Bulk renaming allows users to apply consistent naming conventions to multiple columns in a single operation.
Can I change the prefix value?
Yes. The prefix variable can be modified to match specific naming requirements.
Does this script remove original keys?
Yes. The script replaces the original keys with prefixed keys in the output dataset.
Can I add a suffix instead of a prefix?
Yes. You can modify the new_key assignment to append text after the key name.
Is this method suitable for large datasets?
Yes. This approach scales effectively for datasets with many columns and records.
Notes
- This method assumes a consistent dataset structure.
- Backup original data before applying bulk transformations.
- Follow organizational naming standards.
- Test changes in a staging environment before production use.