Умножение нового столбца на число, если встречается np.where - PullRequest
0 голосов
/ 01 октября 2019

Я пытаюсь умножить этот столбец на число, если условие выполнено. Если это так, я хочу, чтобы столбец august_report ['Monthly Recurring Charge'] умножался на число, например 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))

Ответы [ 2 ]

0 голосов
/ 01 октября 2019

IIUC это то, что вы ищете:

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'))

Если вы хотите сохранить исходное значение, когда условие не выполняется, замените 'condition not met' на august_report['Monthly Recurring Charge']

0 голосов
/ 01 октября 2019

IIUC, это то, что вы ищете

august_report['Activation Commission'] = np.where((august_report['Line activity'] == 'Activation')&(august_report['Activation type'] == 'Lease'),august_report['Activation Commission']*august_report['Monthly Recurring Charge'],"a number")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...