我的for循环不适用于遍历字符串列表

时间:2019-05-10 22:07:38

标签: python pandas for-loop

我想遍历数据集以选择自己选择的变量

Asian_teams=['India','Pakistan','Sri Lanka','Bangladesh']
Top_western_sides=['England','South Africa','New Zealand','Australia']
other_teams=list(set(raw_data['Winner'].unique())-set(Top_western_sides)-set(Asian_teams))

Asian_count=0
western_count=0

for i in range (raw_data.shape[0]):
    for teams in Top_western_sides:
         if raw_data['Host_Country'][i] == teams:
            for asianteams in Asian_teams:
                if raw_data['Winner'][i] == asianteams:
                    Asian_count = Asian_count + 1

            for teams in Top_western_sides:
                if raw_data['Winner'][i] == teams:
                    western_count = western_count + 1

我希望诸如Asian_count和Western_count之类的计数器能够得出结果,但是错误指出“ 255L”是一个关键错误,它指向第9行(如果声明)

0 个答案:

没有答案