如果满足条件该如何创建新列?

时间:2019-07-13 10:10:58

标签: r math division

如果要满足条件,我想创建一个警告列来警告数据库用户。我目前有这样的数据。

      item       stock_need     rto     doi
PRE 24DX4SX15G    200           4800     14
PLS 12RX10SX15G   240           2400     10
ADU 24PX200ML     700           4800      8
NIS 18PX40SX11G   200           3600      4
REF 500GX12D      200           2400     20

如果doi少于14天且rto / doi <= stock_need,我想创建一个新列来警告数据库用户。因此输出将如下所示。

      item       stock_need     rto     doi    rto/doi    warn
PRE 24DX4SX15G    200           4800     14    
PLS 12RX10SX15G   240           2400     10      240    order now
ADU 24PX200ML     700           4800      8      600    order now
NIS 18PX40SX11G   200           3600      4      900
REF 500GX12D      200           2400     20      

如何完成此条件?非常感谢

1 个答案:

答案 0 :(得分:1)

假设您的数据存储在数据帧df中:

total_cost = float(input('enter cost of your dream house: '))
annual_salary = float(input('enter annual salary: '))
portion_saved = float(input('enter percentage of monthly salary to be saved in decimals: '))
monthly_salary = annual_salary/12
saved_portion = monthly_salary*portion_saved
portion_down_payment = 0.25*total_cost
months = 0
current_savings = 0.0

while (portion_down_payment > current_savings):
    current_savings = (current_savings*0.04)/12 + saved_portion
    months = months + 1  

print(months)