pandas 数据框中的产品评分

Product scoring in pandas dataframe

我有产品 ID 数据框。我想通过对每个产品进行评分来找到最好的产品。对于每个变量,值越大,产品得分越高,除了 returns 这意味着更多 returns 更少 score.Also 我需要为变量 Shipped revenue 和 [=19= 分配不同的权重来得分] 这可能会增加 20% 的重要性。

评分函数可以如下所示 Score=ShippedUnits+1.2*ShippedRevenue+OrderedUnits-1.2Returns+View+Stock 其中 0<=分数<=100

请帮忙。谢谢。

 df_product=pd.DataFrame({'ProductId':['1','2','3','4','5','6','7','8','9','10'],'ShippedUnits': 
 [6,8,0,4,27,3,4,14,158,96],'ShippedRevenue':[268,1705,1300,950,1700,33380,500,2200,21000,24565]
 ,'OrderedUnits':[23,78,95,52,60,76,68,92,34,76],'Returns':[0,0,6,0,2,5,6,5,2,13],'View': 
 [0,655,11,378,920,12100,75,1394,12368,14356],'Stock':[24,43,65,27,87,98,798,78,99,231]
             })
 df_product=pd.DataFrame({'ProductId':['1','2','3','4','5','6','7','8','9','10'],'ShippedUnits': 
 [6,8,0,4,27,3,4,14,158,96],'ShippedRevenue':[268,1705,1300,950,1700,33380,500,2200,21000,24565]
 ,'OrderedUnits':[23,78,95,52,60,76,68,92,34,76],'Returns':[0,0,6,0,2,5,6,5,2,13],'View': 
 [0,655,11,378,920,12100,75,1394,12368,14356],'Stock':[24,43,65,27,87,98,798,78,99,231]
             })
df_product['score'] = df_product['ShippedUnits'] +1.2*df_product['ShippedRevenue']+df_product['OrderedUnits']-1.2*df_product['Returns']+df_product['View']+df_product['Stock']

df_product['score']=(df_product['score']-df_product['score'].min())/(df_product['score'].max()-df_product['score'].min())*100

df_product
df["Score"] = df["ShippedUnits"] + df["OrderedUnits"] \
              + df["View"] + df["Stock"] \
              + 1.2 * df["ShippedRevenue"] \
              - 1.2 * df["Returns"]


df["Norm1"] = df["Score"] / df["Score"].max() * 100
df["Norm2"] = df["Score"] / df["Score"].sum() * 100
df["Norm3"] = (df["Score"] - df["Score"].min()) / (df["Score"].max() - df["Score"].min()) * 100
>>> df[["ProductId", "Score", "Norm1", "Norm2", "Norm3"]]
  ProductId    Score       Norm1      Norm2       Norm3
0         1    374.6    0.715883   0.250040    0.000000
1         2   2830.0    5.408298   1.888986    4.726249
2         3   1723.8    3.294284   1.150613    2.596993
3         4   1601.0    3.059606   1.068646    2.360622
4         5   3131.6    5.984673   2.090300    5.306781
5         6  52327.0  100.000000  34.927558  100.000000
6         7   1537.8    2.938827   1.026460    2.238973
7         8   4212.0    8.049382   2.811452    7.386377
8         9  37856.6   72.346208  25.268763   72.146811
9        10  44221.4   84.509718  29.517180   84.398026