如果满足np.where,则将新列乘以数字

时间:2019-10-01 14:04:37

标签: python pandas numpy dataframe multiplying

如果满足条件,我会尝试将此列乘以数字。如果是,我希望将august_report ['每月定期收费']列乘以20之类的数字。

declare @xml as nvarchar(max)

set @xml = N'<monthdate>2019-07-01</monthdate>
<automitemno>302</automitemno>
<amount>1.190000000000</amount>
<currentamount>0.000000000000</currentamount>
<langitemno>1</langitemno>
<monthdate>2019-07-01</monthdate>
<automitemno>2131</automitemno>
<amount>0.386750000000</amount>
<currentamount>0.000000000000</currentamount>
<langitemno>1</langitemno>'


select replace(substring(a.value, charindex('<monthdate>',a.value)+11, charindex('</amount>', a.value)-16), char(10), '') as [XMLValue]

from string_split(replace(@xml, '</langitemno>', char(30)), char(30)) a

where a.value like '%<monthdate>%</amount>%'

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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