存在列的pandas中的属性错误

2024-09-26 22:09:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我第一次和熊猫一起工作,我遇到了一个让我难堪的问题。我试图引用数据帧的一列,但遇到错误。奇怪的是,我可以在我的代码的其他部分引用该列—没问题,但其他部分不行。在

我的代码是:

loops = 0
instability = sys.maxsize
print(team_seasons['season']) #this works
while loops < 1000 and instability > 12000:
    for game in df_reg.itertuples():
        if game.Season == 2016:
            #weight so that late season results are about twice as valueable as early season
            weight = (game.Daynum + 60)/192
            Wrating = team_seasons.loc[(team_seasons['season']==game.season) & (team_seasons['Team_Id']==game.Wteam),'rating']
            Lrating = team_seasons.loc[(team_seasons['season']==game.season) & (team_seasons['Team_Id']==game.Lteam),'rating']
            Wres,Lres = calc_rating(Wrating,Lrating,game.Wscore,game.Lscore)
            print(Wres,Lres)
            break
    break

运行代码时,出现以下错误:

^{pr2}$

有人知道这是怎么回事吗?是因为我试图引用loc语句中的列吗?在


Tags: 代码gameas错误locteamseasonprint

热门问题