输入:
double distanceBetween(Point a, Point b)
如果Petrol_Price> 80:Petrol_Price = 80,否则:数据框中给出的Petrol_Price
新价格=现有票价+汽油价格+ 2 *加薪远足
2。排列正确的顺序。
输出
import pandas as pd
data = [['abc1',55,98,100],['abc2',56,97,101],['abc3',13,18,55],['abc4',56,79,100]]
df = pd.DataFrame(data,columns=['Bus','Existing_Fare','Petrol_Price','Salary_Hike'])
答案 0 :(得分:3)
IIUC:
df.assign(
Petrol_Price=df.Petrol_Price.clip(0, 80)
).eval(
'New_Price=Existing_Fare + Petrol_Price + 2 * Salary_Hike'
).assign(
Rank_Duplicates=lambda d: d.New_Price.rank(method='dense', ascending=False)
)
Bus Existing_Fare Petrol_Price Salary_Hike New_Price Rank_Duplicates
0 abc1 55 80 100 335 2.0
1 abc2 56 80 101 338 1.0
2 abc3 13 18 55 141 3.0
3 abc4 56 79 100 335 2.0