我试图确定我的输入表的价格,它具有特定的行业类型和平均每月交易基于参考表1具有不同行业的价格(这些代表A层价格)和参考表2根据平均每月交易对价格层进行分类参考表1具有所有行业的定价层A的价格B层的价格计算为A层价格的90%;C层的价格计算为B层价格的90%,依此类推
输入表
参考表1
参考表2
输出表
Python代码尝试
import pandas as pd
df1=pd.read_csv("input.csv")
df2=pd.read_csv("reference1.csv")
df3=pd.read_csv("reference2.csv")
industry =df1[industry]
avgmonthlytransaction=df1[Avg Monthly Transactions]
price=df1.where(df1[avg Monthly Transactions]>=df3[min average] & <=df3[maximum average],pricingtier)
&& df1.where(df1[industry]=df2[Industry],df2[Price]
df3['factor'] = [0.9**i for i in range(6)]
df3
使用cut()
创建仓,找到对应的定价层
,我们可以通过df3
映射其因子
。
tier = pd.cut(
df1['Avg Monthly Transactions'],
bins=(df3.iloc[:,1].values.tolist() + [np.inf]),
labels=df3['Pricing Tier'].values.tolist())
tier = tier.to_frame(name='Pricing Tier')
output = df1.merge(df2, on='Industry', how='left')
output['price'] = output['price']*tier.merge(df3[['Pricing Tier','factor']], on='Pricing Tier', how='left')['factor']
###
Industry Avg Monthly Transactions price
0 Automotive 1129 28.3500
1 Financial Services 7219 26.2440
2 Retail 11795 17.7147
3 Financial Services 10092 23.6196
4 Retail 9445 19.6830