【问题标题】:Product scoring in pandas dataframe熊猫数据框中的产品评分
【发布时间】:2021-07-25 21:40:25
【问题描述】:

我确实有产品 ID 数据框。我想通过对每个产品进行评分来找到最好的产品。对于每个变量,值越大,产品得分就越高,除了退货,这意味着退货越多得分越少。此外,我需要为变量分配不同的权重来评分发货收入和退货,这可能会增加其重要性的 20%。

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

请帮忙。谢谢。

 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]
             })

【问题讨论】:

  • 鉴于您的dataframe,您期望得到什么?
  • 实际上我为每个产品添加了一个分数,0 分和 100 分,谢谢
  • 您的权重不能确保分数在 [0, 100] 范围内。
  • 没关系,它可以超过 100,但我们可以将所有分数压缩到 100,谢谢
  • 这是实现它的一种方法,w = np.array([1,1.2,1,-1.2,1, 1])score = df_product.drop('ProductId', axis=1).apply(lambda x: sum(w*x), axis=1)normalizedScore = 100*(score - score.min())/(score.max() - score.min())

标签: python pandas product segment


【解决方案1】:
 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

【讨论】:

  • 我们能把分数挤到 0 和 100 之间吗。谢谢
  • 也许缩放每个变量 btw 0 和 100 然后求和?
  • 我将0-1之间的列标准化并乘以100
【解决方案2】:
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

【讨论】:

    猜你喜欢
    • 2021-09-03
    • 2023-03-20
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    相关资源
    最近更新 更多