我有一個CSV格式的資料集,以二維陣列形式匯入:
我有一個CSV格式的資料集,以二維陣列形式匯入。
game_id, player_score, rounds_played
0, 56, 30.
0, 44, 30.
1, 77, 26.
1, 34, 26.
2, 36, 23.
2, 31, 23.
在下一步中,我需要創建一個新的陣列,其中的player_score需要與每場比賽中的rounds_played相對應,以獲得僅看分數時的表現的估計。
在一個 "for回圈 "中,我做了一些類似的事情,我計算了每個分數與所打回合的 "權重",然后再次將系數乘以回合數:
給定,30是這個集合中的最大回合數_played值:
。weight = (player_score * rounds_played) / 30
new_score = weight
然后我將new_score追加到一個新的陣列中。
如果我有一個較大的2D陣列,這可能會變得相當慢。- 有沒有一種更簡短、更直接的方法(也許在numpy中)來創建一個帶有修正分數的新陣列?
uj5u.com熱心網友回復:
你可以在pandas中輕松而快速地做到這一點(感謝python的矢量化)。
df['new_score'] = (df.player_score * df.rounds_played) / 30
結果 df:
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/326866.html
標籤:
上一篇:尋找用戶的兩個輸入之間的平均值

