請貼 code
不要貼圖
打得好累
圖片有夠糊
import pandas as pd
subject = ['國文', '英文', '數甲', '數乙', '物理', '化學', '生物', '歷史', '地理', '公民'
]
major = ['土木系', '財政系']
wg = [
[2, 2, 0, 1, 0, 0, 0, 1, 1, 0],
[1, 1.5, 0, 1.5, 0, 0, 0, 0, 0, 0],
]
score = [86.5, 79.4, 88.2, 96.5, 86.3, 76.8, 96.1, 78.5, 82.4, 88.6]
df2 = pd.DataFrame(wg, index = major, columns = subject)
df2['加權分數'] = df2.dot(score)
df2
用迴圈你乾脆不要用pandas...
import pandas as pd
score = pd.Series([86.5, 79.4, 88.2, 96.5, 86.3, 76.8, 96.1, 78.5, 82.4, 88.6])
weight = pd.DataFrame(data=[
[2,2,0,1,0,0,0,1,1,0],
[1,1.5,0,1.5,0,0,0,0,0,0]
])
weight['加權分數'] = weight.dot(score)
print(weight)
多筆分數:
import pandas as pd
scores = pd.DataFrame([
[86.5, 79.4, 88.2, 96.5, 86.3, 76.8, 96.1, 78.5, 82.4, 88.6],
[87, 79, 90, 93.5, 96.3, 86.8, 95.1, 78.6, 86.4, 78.6]
])
weight = pd.DataFrame(data=[
[2,2,0,1,0,0,0,1,1,0],
[1,1.5,0,1.5,0,0,0,0,0,0]
])
# 矩鎮內積,所以有一方要轉置
print(weight.dot(scores.T))