当我尝试执行此函数时,出现类型错误
for i, value in enumerate(line_score):
print(i, value)
if (value["GAME_SEQUENCE"] != game_sequence):
game_sequence += 1
TypeError:字符串索引必须是整数
line_sccore的值是
GAME_DATE_EST GAME_SEQUENCE GAME_ID TEAM_ID
0 2018-02-15T00:00:00 1 0021700865 1610612743
1 2018-02-15T00:00:00 1 0021700865 1610612749
2 2018-02-15T00:00:00 2 0021700866 1610612747
3 2018-02-15T00:00:00 2 0021700866 1610612750
print(i, value)
提供0 GAME_DATE_EST
答案 0 :(得分:1)
我假设您想计算game_sequence中的游戏数量,其中game_sequence是一个简单的变量?
我使用了您提供的数据集。
for c in aps1.columns:
print ('{}, Range in {} to {}'.format(c, aps1[c].min(), round(aps1[c].max())))
S22, Range in 2 to 9
S23, Range in 0 to 7
S26, Range in 2 to 9
S3, Range in 4 to 5
如果GAME_SEQUENCE(在数据集中)的值不同,此代码会向game_sequence添加+1。
line_score = pd.DataFrame({"GAME_DATA_EST":["2018-02-15T00:00:00","2018-02-15T00:00:00","2018-02-15T00:00:00","2018-02-15T00:00:00"],
"GAME_SEQUENCE":[1,1,2,2],
"GAME_ID":["0021700865","0021700865","0021700866","0021700866"],
"TEAM_ID":[1610612743,1610612749 ,1610612747,1610612750]})
如果你的意思不同,请告诉我。
答案 1 :(得分:-4)
value ['game-sequence']引用称为'value'的字典,显然'value'不是你认为的字典,但它是一个字符串,你实际上可以在字符串中引用字符喜欢列表,需要整数