Search code examples
pythonpandasnumpydataframemultiplication

Multiplying a new column by a number if the np.where is met


I am trying to multiply this column by a number if the condition is met. If it is I want the august_report['Monthly Recurring Charge'] column to be multiplied by a number such as 20.

august_report['Activation Commission'] = np.where((august_report['Line activity'] == 'Activation')&(august_report['Activation type'] == 'Lease'),np.multiply(august_report['Monthly Recurring Charge'],20))

Solution

  • IIUC this is what you're looking for:

    august_report['Activation Commission'] = np.where((august_report['Line activity'] == 'Activation')&(august_report['Activation type'] == 'Lease'),august_report['Monthly Recurring Charge']*20, 'condition not met'))
    

    If you want to preserve the original value when the condition isn't met you replace 'condition not met' by august_report['Monthly Recurring Charge']