如何修复 'DataFrame' object is not callable 的计算错误

how to fix the calculation error which says 'DataFrame' object is not callable

我正在处理足球数据集,这是我收到的以下错误。请帮助,

#what is the win rate of HomeTeam?





n_matches = df.shape[0]



n_features = df.shape[1] -1

n_homewin = len(df(df.FTR == 'H'))

win_rate = (float(n_homewin) / (n_matches)) * 100

print ("Total number of matches,{}".format(n_matches))
print ("Number of features,{}".format(n_features))
print ("Number of maches won by hom team,{}".format (n_homewin))
print ("win rate of home team,{:.2f}%" .format(win_rate))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-122-7e4d81fc684e> in <module>
      5 n_features = df.shape[1] -1
      6 
----> 7 n_homewin = len(df(df.FTR == 'H'))
      8 
      9 win_rate = (float(n_homewin) / (n_matches)) * 100

TypeError: 'DataFrame' 对象不是 预期结果应该打印球队胜率

你应该修改为df[df.FTR == 'H']。括号暗示函数调用

我认为 () 有问题,需要 [] 过滤 boolean indexing:

n_homewin = len(df[df.FTR == 'H'])

或更简单地计算 Trues 个值 sum:

n_homewin = (df.FTR == 'H').sum()