0
我有以下代碼。將值附加到python列表中
rushingyards = 0
passingyards = 0
templist = []
combineddf = play.groupby(['GameCode','PlayType']).sum()
combineddf.to_csv('data/combined.csv', sep=',')
combineddff =pd.DataFrame.from_csv('data/combined.csv')
temp = {}
for row in combineddff.itertuples():
if row[1] in ('RUSH', 'PASS'):
temp['GameCode'] = row[0]
if row[1] == 'RUSH':
temp['Rushingyards'] = row[10]
else:
temp['PassingYards'] = row[10]
else:
continue
templist.append(temp)
我的聯合csv的頭在下面。
PlayType PlayNumber PeriodNumber Clock OffenseTeamCode \
GameCode
2047220131026 ATTEMPT 779 19 2220 1896
2047220131026 FIELD_GOAL 351 9 1057 946
2047220131026 KICKOFF 1244 32 4388 3316
2047220131026 PASS 8200 204 6549 14730
2047220131026 PENALTY 1148 29 1481 2372
DefenseTeamCode OffensePoints DefensePoints Down Distance \
GameCode
2047220131026 1896 142 123 NaN NaN
2047220131026 476 52 51 12 17
2047220131026 2846 231 195 NaN NaN
2047220131026 23190 1131 1405 147 720
2047220131026 2842 188 198 19 84
Spot DriveNumber DrivePlay
GameCode
2047220131026 24 NaN NaN
2047220131026 19 49 3
2047220131026 850 NaN NaN
2047220131026 3719 1161 80
2047220131026 514 164 1
我必須檢查playtype是Rush還是pass,並相應地創建一個如下列表。
Gamecode rushing_yards passingyards
299004720130829 893 401
299004720130824 450 657
299004720130821 430 357
我無法正確追加值。 Evey運行它的時間,它給出了所有類似的遊戲代碼,rushing_yards和passingyards的值。請幫助。
您可以通過將代碼簡化爲問題的最小示例來改善此問題。請參閱https://stackoverflow.com/help/mcve –