存在的列{4}的pandas中的属性错误

时间:2017-02-27 06:34:20

标签: python pandas

我第一次和熊猫一起工作,我遇到了一个真正难以理解的问题。我正在尝试引用数据帧的一列,但是我收到了一个错误。奇怪的是,我可以在我的代码的其他部分引用该列没有问题,但不能引用其他部分。

这是我的代码:

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

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

AttributeError: 'Pandas' object has no attribute 'season'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-56-eacf72e4fe01> in <module>()
      8             #weight so that late season results are about twice as valueable as early season
      9             weight = (game.Daynum + 60)/192
---> 10             Wrating = team_seasons.loc[(team_seasons['season']==game.season) & (team_seasons['Team_Id']==game.Wteam),'rating']
     11             Lrating = team_seasons.loc[(team_seasons['season']==game.season) & (team_seasons['Team_Id']==game.Lteam),'rating']
     12             Wres,Lres = calc_rating(Wrating,Lrating,game.Wscore,game.Lscore)

AttributeError: 'Pandas' object has no attribute 'season'

有谁知道这里发生了什么?是因为我试图在loc语句中引用该列吗?

0 个答案:

没有答案