Skip to content
Advertisement

Replace value based on a corresponding value but keep value if criteria not met

Given the following dataframe,

INPUT df:

Cost_centre Pool_costs
90272 A
92705 A
98754 A
91350 A

Replace Pool_costs value with ‘B’ given the Cost_centre value but keep the Pool_costs value if the Cost_centre value does not appear in list.

OUTPUT df:

Cost_centre Pool_costs
90272 B
92705 A
98754 A
91350 B

Current Code:

This code works up until the else side of lambda; finding the Pool_costs value again is the hard part.

JavaScript

I have used the following and have found success but it gets hard to read and modify when there are a lot of cost_centre’s to change.

JavaScript

Advertisement

Answer

IIUC, you can use isin

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement