Apply Transform to Column
Medium
pandas
DoorDash
Airbnb
Given a list of dictionaries and a transform function, apply the function to a specified column and return the updated dataset with a new column.
Example
data = [{"name": "Alice", "salary": 50000}, {"name": "Bob", "salary": 60000}]
apply_transform(data, "salary", "salary_k", lambda x: x / 1000)
# => [{"name": "Alice", "salary": 50000, "salary_k": 50.0}, {"name": "Bob", "salary": 60000, "salary_k": 60.0}]
Test Cases
Python Editor
Output
Click "Run" to see results...