【发布时间】:2021-07-08 17:00:46
【问题描述】:
想计算乘法。为此,我想将行值转换为 Df1 的列
所以 Df1 矩阵可以是 [6x1] 而 Df2 是 [1x6]
结果 = [1x6] * [6x1]
Df1:
Tech_ID s1 s2 s3 s4 s5 s6
-------------------------------
1 1 1 1 0 1 1
2 1 0 1 1 1 0
3 1 1 0 0 1 1
Df1 = {'Tech_ID':[1,2,3],
'S1':[1,1,1], 'S2':[1,0,1], 'S3': [1,1,0],
'S4':[0,1,0],'S5':[1,1,1],'S6':[1,0,1]}
Df2:
Tech_ID Std_Id s1_Norm s2 Norm S3 Norm S4_Norm S5 Norm S6_Norm
---------------------------------------------------------------------
1 1 0.87 0.87 0.27 0.83 0.37 0.83
1 7 0.25 0.45 0.45 0.28 0.15 0.22
2 4 0.38 0.38 0.58 0.31 0.28 0.32
3 8 0.44 0.24 0.64 0.40 0.44 0.48
2 2 0.73 0.43 0.33 0.78 0.53 0.75
Df2 = {'Tech_ID':[1,1,2,3,2], Std_Id [1,7,4,8,2]
'S1_norm':[0.87,0.25,0.38,0.44,0.73], 'S2_norm':[0.87,0.45,0.38,0.24,0.43],
'S3_norm': [0.27,0.45,0.58,0.64,0.33], 'S4_norm':[0.83,0.28,0.31,0.40,0.78],
'S5_norm': [0.37,0.15,0.28,0.44,0.53], 'S6_norm':[0.83,0.22,0.32,0.48,0.75],}
计算说明,
[Df2] X [Df1]
_ _
| |
_ _ | S1 |
| | | S2 |
| s1_Norm s2 Norm S3 Norm S4_Norm S5 Norm S6_Norm | X | S3 |
|_ _| | S4 |
| S5 |
| S6 |
|_ _|
对于 Tech_ID:1 和 Std_Id:1
_ _
| |
_ _ | 1 |
| | | 1 |
| 0.87 0.87 0.27 0.83 0.37 0.83 | X | 1 | = 3.21
|_ _| | 0 |
| 1 |
| 1 |
|_ _|
* Result= 3.21
* Final result = Result/ Length(count) of values = 3.21/6 = 0.535
预期结果:
Tech_ID Std_Id Result Final_Res
-----------------------------------
1 1 3.21 0.535
1 7 2.13 0.355
2 4 1.55 0.258
3 8 1.87 0.312
2 2 2.37 0.395
对如何将这些理论概念转换成 python 脚本感到困惑。
【问题讨论】:
标签: python pandas numpy matrix