語句下面的代碼必須執行幾個步驟:應用嵌套如果上DF
- 如果列「批發數據」用法> =列「MBS」比
- 減去列「批發數據」 - 「MBS 「
乘法基於下表
- 32上的差 - 0.56
- 64 - 0.5
- 128 - 0.4
- 256 - 0.4
- 512 - 0.3
- 1024 - 0.3
- 其他所有可能的選項 - 0
我有下面的代碼
if df['Wholesale Data Usage'] >= df['mbs']:
if df['mbs'] == "32":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.5
elif df['mbs'] == "64":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.5
elif df['mbs'] == "128":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.4
elif df['mbs'] == "256":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.4
elif df['mbs'] == "512":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.3
elif df['mbs'] == "1024":
df['Additional Charge'] = (df['Wholesale Data Usage'] - df[
'mbs']) * 0.3
else:
df['Additional Charge'] = 0
else:
df['Additional Charge'] = 0
不知道我在做什麼wr翁。
縮進是錯誤的開始和結束。您似乎有兩個'else'語句,但使用不正確的縮進很難知道。你可能會考慮爲表格使用字典,它會更簡單。 – cdarke