不能用灵活型进行缩减

cha*_*cab 5 python numpy python-2.7

我有这个数据集:

           Game1    Game2   Game3   Game4     Game5

Player1       2        6        5       2        2

Player2       6        4        1       8        4

Player3       8        3        2       1        5

Player4       4        9        4       7        9
Run Code Online (Sandbox Code Playgroud)

我想为每个玩家计算5场比赛的总和.

这是我的代码:

import csv
f=open('Games','rb')
f=csv.reader(f,delimiter=';')
lst=list(f)
lst
import numpy as np
myarray = np.asarray(lst)
x=myarray[1,1:] #First player
y=np.sum(x)
Run Code Online (Sandbox Code Playgroud)

我有错误"无法使用灵活类型执行缩减".我真的很陌生,我需要你的帮助.

谢谢

Max*_*axU 1

考虑使用Pandas 模块

import pandas as pd

df = pd.read_csv('/path/to.file.csv', sep=';')
Run Code Online (Sandbox Code Playgroud)

生成的数据框:

In [196]: df
Out[196]:
         Game1  Game2  Game3  Game4  Game5
Player1      2      6      5      2      2
Player2      6      4      1      8      4
Player3      8      3      2      1      5
Player4      4      9      4      7      9
Run Code Online (Sandbox Code Playgroud)

和:

In [197]: df.sum(axis=1)
Out[197]:
Player1    17
Player2    23
Player3    19
Player4    33
dtype: int64

In [198]: df.sum(1).values
Out[198]: array([17, 23, 19, 33], dtype=int64)
Run Code Online (Sandbox Code Playgroud)