Pandas 如何修正表示为';数据帧';对象不可调用

Pandas 如何修正表示为';数据帧';对象不可调用,pandas,jupyter-notebook,sklearn-pandas,Pandas,Jupyter Notebook,Sklearn Pandas,我正在处理足球数据集,这是我得到的以下错误。请帮忙 #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,{}".forma

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

#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
#主队的获胜率是多少?
n_matches=df.shape[0]
n_特征=df.形状[1]-1
n_homewin=len(df(df.FTR='H'))
赢率=(浮动(n场主场赢)/(n场比赛))*100
打印(“匹配的总数,{}”。格式(n_匹配))
打印(“特征数量,{}”。格式(n_特征))
打印(“hom团队赢得的马赫数,{}”。格式(n_homewin))
打印(“主队获胜率,{.2f}%”。格式(获胜率))
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在里面
5 n_特征=df.形状[1]-1
6.
---->7 n_homewin=len(df(df.FTR='H'))
8.
9赢率=(浮动(n场主场赢)/(n场比赛))*100
TypeError:“DataFrame”对象不可用
预期结果应打印团队获胜率

您应将其修改为
df[df.FTR=='H']
。括号表示函数调用

我认为问题在于
()
,需要
[]
进行筛选:

或更简单的计数
True
s通过
sum

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

非常感谢,先生,这真的如你所说的那样有效。非常感谢你的帮助,先生,这确实如你所说的那样有效。
n_homewin = (df.FTR == 'H').sum()