我正在导入一个csv文件来运行一些统计信息,但是我在查询数据集时遇到了问题。一旦我加载它,并且一旦我对它运行查询,它似乎破坏了程序触及的dicts。没有更多'复制'行,即使thogh评估它仍然返回一个DictReader对象
import csv
database = open("C:/Users/Carlos/Downloads/SP1.csv.csv")
copy = csv.DictReader(database)
def select_HomeTeam_matches (team):
matches = []
for row in copy:
if row['HomeTeam'] == team:
matches.append(row)
return matches
def avg_home_goals (team):
matches = 0
goals = 0
for row in select_HomeTeam_matches(team):
matches += 1
goals += int(match['FTHG'])
return goals/matches
print(select_HomeTeam_matches('Valencia'),
select_HomeTeam_matches('Barcelona'),
select_HomeTeam_matches('Real Madrid'),
select_HomeTeam_matches('Valencia'))
[{'FTHG': '1', 'AwayTeam': 'La Coruna', 'HC': '5', 'VCA': '9', 'VCD': '4.8', 'HTAG': '1', 'VCH': '1.4', 'HTR': 'D', 'BbAvH': '1.41', 'HomeTeam': 'Valencia', 'PSH': '1.4', 'PSCH': '1.49', 'FTR': 'D', 'BbAHh': '-1', 'BbMxH': '1.5', 'AST': '3', 'HR': '1', 'BbAvAHH': '1.65', 'BbMx<2.5': '2.06', 'LBA': '7.5', 'AC': '7', 'B365A': '8', 'PSCD': '4.4', 'AS': '12', 'AY': '1', 'BbMxD': '4.86', 'IWD': '4', 'BbMxAHA': '2.41', 'BbAvA': '8.02', 'PSCA': '8.12', 'Div': 'SP1', 'LBH': '1.44', 'IWA': '7', 'Bb1X2': '37', 'BbMxAHH': '1.7', 'HF': '13', 'HST': '5', 'HS': '12', 'WHD': '4.2', 'BbAv<2.5': '1.97', 'LBD': '4.33', 'PSA': '10.04', 'FTAG': '1', 'BbAH': '24', 'HY': '2', 'B365H': '1.44', 'BbOU': '35', 'IWH': '1.45', 'HTHG': '1', 'BbAvAHA': '2.27', 'B365D': '4.33', 'AF': '15', 'BbMxA': '10.04', 'BbAvD': '4.42', 'WHH': '1.44', 'WHA': '7.5', 'PSD': '4.86', 'Date': '30/08/15', 'BbAv>2.5': '1.81', 'BWA': '7.75', 'AR': '0', 'BbMx>2.5': '1.88', 'BWD': '4', 'BWH': '1.44'}, {'FTHG': '0', 'AwayTeam': 'Betis', 'HC': '7', 'VCA': '7', 'VCD': '4.5', 'HTAG': '0', 'VCH': '1.5', 'HTR': 'D', 'BbAvH': '1.49', 'HomeTeam': 'Valencia', 'PSH': '1.52', 'PSCH': '1.49', 'FTR': 'D', 'BbAHh': '-1', 'BbMxH': '1.53', 'AST': '1', 'HR': '0', 'BbAvAHH': '1.84', 'BbMx<2.5': '2.19', 'LBA': '6.5', 'AC': '1', 'B365A': '6.5', 'PSCD': '4.86', 'AS': '3', 'AY': '2', 'BbMxD': '4.74', 'IWD': '4', 'BbMxAHA': '2.08', 'BbAvA': '6.67', 'PSCA': '7.11', 'Div': 'SP1', 'LBH': '1.53', 'IWA': '6.1', 'Bb1X2': '37', 'BbMxAHH': '1.88', 'HF': '17', 'HST': '5', 'HS': '22', 'WHD': '4', 'BbAv<2.5': '2.1', 'LBD': '4', 'PSA': '7.02', 'FTAG': '0', 'BbAH': '24', 'HY': '4', 'B365H': '1.5', 'BbOU': '33', 'IWH': '1.5', 'HTHG': '0', 'BbAvAHA': '2.02', 'B365D': '4.33', 'AF': '15', 'BbMxA': '7.02', 'BbAvD': '4.27', 'WHH': '1.53', 'WHA': '6.5', 'PSD': '4.59', 'Date': '19/09/15', 'BbAv>2.5': '1.72', 'BWA': '6.75', 'AR': '1', 'BbMx>2.5': '1.79', 'BWD': '4.4', 'BWH': '1.5'}, {'FTHG': '1', 'AwayTeam': 'Granada', 'HC': '11', 'VCA': '7.5', 'VCD': '4.4', 'HTAG': '0', 'VCH': '1.5', 'HTR': 'H', 'BbAvH': '1.45', 'HomeTeam': 'Valencia', 'PSH': '1.47', 'PSCH': '1.45', 'FTR': 'H', 'BbAHh': '-1', 'BbMxH': '1.5', 'AST': '3', 'HR': '0', 'BbAvAHH': '1.73', 'BbMx<2.5': '2.05', 'LBA': '7.5', 'AC': '3', 'B365A': '7.5', 'PSCD': '4.62', 'AS': '18', 'AY': '3', 'BbMxD': '4.63', 'IWD': '4', 'BbMxAHA': '2.23', 'BbAvA': '7.64', 'PSCA': '8.9', 'Div': 'SP1', 'LBH': '1.44', 'IWA': '6.1', 'Bb1X2': '42', 'BbMxAHH': '1.77', 'HF': '19', 'HST': '5', 'HS': '12', 'WHD': '4.2', 'BbAv<2.5': '1.96', 'LBD': '4.5', 'PSA': '8.23', 'FTAG': '0', 'BbAH': '25', 'HY': '3', 'B365H': '1.45', 'BbOU': '38', 'IWH': '1.5', 'HTHG': '1', 'BbAvAHA': '2.14', 'B365D': '4.5', 'AF': '20', 'BbMxA': '8.37', 'BbAvD': '4.36', 'WHH': '1.44', 'WHA': '8', 'PSD': '4.61', 'Date': '25/09/15', 'BbAv>2.5': '1.84', 'BWA': '7', 'AR': '0', 'BbMx>2.5': '1.92', 'BWD': '4.33', 'BWH': '1.48'}, {'FTHG': '3', 'AwayTeam': 'Malaga', 'HC': '6', 'VCA': '6.25', 'VCD': '4.1', 'HTAG': '0', 'VCH': '1.62', 'HTR': 'H', 'BbAvH': '1.62', 'HomeTeam': 'Valencia', 'PSH': '1.65', 'PSCH': '1.57', 'FTR': 'H', 'BbAHh': '-1', 'BbMxH': '1.67', 'AST': '3', 'HR': '0', 'BbAvAHH': '2.09', 'BbMx<2.5': '1.9', 'LBA': '5.5', 'AC': '8', 'B365A': '6', 'PSCD': '4.1', 'AS': '10', 'AY': '3', 'BbMxD': '4.16', 'IWD': '3.7', 'BbMxAHA': '1.82', 'BbAvA': '5.73', 'PSCA': '7.22', 'Div': 'SP1', 'LBH': '1.62', 'IWA': '5.4', 'Bb1X2': '44', 'BbMxAHH': '2.17', 'HF': '18', 'HST': '3', 'HS': '6', 'WHD': '3.4', 'BbAv<2.5': '1.82', 'LBD': '3.8', 'PSA': '5.91', 'FTAG': '0', 'BbAH': '27', 'HY': '3', 'B365H': '1.62', 'BbOU': '39', 'IWH': '1.6', 'HTHG': '2', 'BbAvAHA': '1.78', 'B365D': '3.75', 'AF': '21', 'BbMxA': '6.25', 'BbAvD': '3.84', 'WHH': '1.67', 'WHA': '6', 'PSD': '4.09', 'Date': '17/10/15', 'BbAv>2.5': '1.98', 'BWA': '5.5', 'AR': '0', 'BbMx>2.5': '2.06', 'BWD': '3.8', 'BWH': '1.65'}, {'FTHG': '3', 'AwayTeam': 'Levante', 'HC': '5', 'VCA': '8.5', 'VCD': '4.6', 'HTAG': '0', 'VCH': '1.45', 'HTR': 'D', 'BbAvH': '1.44', 'HomeTeam': 'Valencia', 'PSH': '1.46', 'PSCH': '1.55', 'FTR': 'H', 'BbAHh': '-1.5', 'BbMxH': '1.5', 'AST': '5', 'HR': '0', 'BbAvAHH': '2.31', 'BbMx<2.5': '1.93', 'LBA': '7.5', 'AC': '5', 'B365A': '7.5', 'PSCD': '4.23', 'AS': '10', 'AY': '3', 'BbMxD': '4.68', 'IWD': '4.4', 'BbMxAHA': '1.67', 'BbAvA': '7.67', 'PSCA': '7.21', 'Div': 'SP1', 'LBH': '1.44', 'IWA': '7.3', 'Bb1X2': '48', 'BbMxAHH': '2.38', 'HF': '19', 'HST': '6', 'HS': '13', 'WHD': '4.2', 'BbAv<2.5': '1.85', 'LBD': '4.2', 'PSA': '8.39', 'FTAG': '0', 'BbAH': '28', 'HY': '2', 'B365H': '1.44', 'BbOU': '42', 'IWH': '1.4', 'HTHG': '0', 'BbAvAHA': '1.64', 'B365D': '4.5', 'AF': '21', 'BbMxA': '8.5', 'BbAvD': '4.35', 'WHH': '1.44', 'WHA': '8', 'PSD': '4.6', 'Date': '31/10/15', 'BbAv>2.5': '1.94', 'BWA': '7.5', 'AR': '0', 'BbMx>2.5': '2.05', 'BWD': '4.1', 'BWH': '1.45'}, {'FTHG': '1', 'AwayTeam': 'Las Palmas', 'HC': '1', 'VCA': '7', 'VCD': '4.33', 'HTAG': '0', 'VCH': '1.53', 'HTR': 'H', 'BbAvH': '1.5', 'HomeTeam': 'Valencia', 'PSH': '1.53', 'PSCH': '1.51', 'FTR': 'D', 'BbAHh': '-1', 'BbMxH': '1.55', 'AST': '7', 'HR': '0', 'BbAvAHH': '1.88', 'BbMx<2.5': '2.1', 'LBA': '6.5', 'AC': '8', 'B365A': '7.5', 'PSCD': '4.42', 'AS': '18', 'AY': '3', 'BbMxD': '4.55', 'IWD': '4.4', 'BbMxAHA': '2.08', 'BbAvA': '6.76', 'PSCA': '7.54', 'Div': 'SP1', 'LBH': '1.5', 'IWA': '7.3', 'Bb1X2': '45', 'BbMxAHH': '1.93', 'HF': '22', 'HST': '3', 'HS': '9', 'WHD': '3.8', 'BbAv<2.5': '1.95', 'LBD': '4', 'PSA': '7.21', 'FTAG': '1', 'BbAH': '27', 'HY': '3', 'B365H': '1.44', 'BbOU': '40', 'IWH': '1.4', 'HTHG': '1', 'BbAvAHA': '1.98', 'B365D': '4.2', 'AF': '12', 'BbMxA': '7.5', 'BbAvD': '4.16', 'WHH': '1.53', 'WHA': '7', 'PSD': '4.38', 'Date': '21/11/15', 'BbAv>2.5': '1.85', 'BWA': '6.75', 'AR': '0', 'BbMx>2.5': '1.92', 'BWD': '4.25', 'BWH': '1.5'}, {'FTHG': '1', 'AwayTeam': 'Barcelona', 'HC': '0', 'VCA': '1.33', 'VCD': '5.5', 'HTAG': '0', 'VCH': '10', 'HTR': 'D', 'BbAvH': '9.26', 'HomeTeam': 'Valencia', 'PSH': '10.05', 'PSCH': '13.45', 'FTR': 'D', 'BbAHh': '1.5', 'BbMxH': '10.05', 'AST': '5', 'HR': '0', 'BbAvAHH': '2.03', 'BbMx<2.5': '3.1', 'LBA': '1.3', 'AC': '6', 'B365A': '1.3', 'PSCD': '7.25', 'AS': '16', 'AY': '1', 'BbMxD': '6.05', 'IWD': '4.8', 'BbMxAHA': '1.87', 'BbAvA': '1.31', 'PSCA': '1.24', 'Div': 'SP1', 'LBH': '9', 'IWA': '1.33', 'Bb1X2': '50', 'BbMxAHH': '2.09', 'HF': '13', 'HST': '3', 'HS': '10', 'WHD': '5.5', 'BbAv<2.5': '2.88', 'LBD': '5.75', 'PSA': '1.33', 'FTAG': '1', 'BbAH': '29', 'HY': '3', 'B365H': '9', 'BbOU': '36', 'IWH': '8.3', 'HTHG': '0', 'BbAvAHA': '1.83', 'B365D': '6', 'AF': '15', 'BbMxA': '1.33', 'BbAvD': '5.57', 'WHH': '9', 'WHA': '1.3', 'PSD': '5.95', 'Date': '05/12/15', 'BbAv>2.5': '1.4', 'BWA': '1.3', 'AR': '0', 'BbMx>2.5': '1.44', 'BWD': '5.5', 'BWH': '10'}, {'FTHG': '2', 'AwayTeam': 'Getafe', 'HC': '5', 'VCA': '5.5', 'VCD': '3.8', 'HTAG': '2', 'VCH': '1.73', 'HTR': 'D', 'BbAvH': '1.67', 'HomeTeam': 'Valencia', 'PSH': '1.69', 'PSCH': '1.77', 'FTR': 'D', 'BbAHh': '-1', 'BbMxH': '1.73', 'AST': '3', 'HR': '0', 'BbAvAHH': '2.23', 'BbMx<2.5': '1.85', 'LBA': '5.25', 'AC': '1', 'B365A': '5.5', 'PSCD': '3.75', 'AS': '9', 'AY': '6', 'BbMxD': '3.87', 'IWD': '3.7', 'BbMxAHA': '1.73', 'BbAvA': '5.49', 'PSCA': '5.32', 'Div': 'SP1', 'LBH': '1.67', 'IWA': '5.4', 'Bb1X2': '48', 'BbMxAHH': '2.31', 'HF': '13', 'HST': '7', 'HS': '12', 'WHD': '3.6', 'BbAv<2.5': '1.79', 'LBD': '3.6', 'PSA': '5.81', 'FTAG': '2', 'BbAH': '27', 'HY': '2', 'B365H': '1.67', 'BbOU': '43', 'IWH': '1.6', 'HTHG': '2', 'BbAvAHA': '1.69', 'B365D': '3.75', 'AF': '20', 'BbMxA': '5.94', 'BbAvD': '3.69', 'WHH': '1.67', 'WHA': '5.5', 'PSD': '3.87', 'Date': '19/12/15', 'BbAv>2.5': '2', 'BWA': '5.5', 'AR': '0', 'BbMx>2.5': '2.09', 'BWD': '3.8', 'BWH': '1.67'}, {'FTHG': '2', 'AwayTeam': 'Real Madrid', 'HC': '4', 'VCA': '1.57', 'VCD': '4.6', 'HTAG': '1', 'VCH': '5.5', 'HTR': 'D', 'BbAvH': '5.6', 'HomeTeam': 'Valencia', 'PSH': '5.87', 'PSCH': '6.6', 'FTR': 'D', 'BbAHh': '1', 'BbMxH': '6', 'AST': '4', 'HR': '0', 'BbAvAHH': '1.95', 'BbMx<2.5': '2.75', 'LBA': '1.57', 'AC': '7', 'B365A': '1.53', 'PSCD': '4.76', 'AS': '17', 'AY': '1', 'BbMxD': '4.72', 'IWD': '4', 'BbMxAHA': '1.96', 'BbAvA': '1.55', 'PSCA': '1.52', 'Div': 'SP1', 'LBH': '5.25', 'IWA': '1.55', 'Bb1X2': '49', 'BbMxAHH': '2.01', 'HF': '18', 'HST': '4', 'HS': '11', 'WHD': '3.8', 'BbAv<2.5': '2.59', 'LBD': '4.33', 'PSA': '1.57', 'FTAG': '2', 'BbAH': '30', 'HY': '1', 'B365H': '6', 'BbOU': '38', 'IWH': '5.5', 'HTHG': '1', 'BbAvAHA': '1.9', 'B365D': '4.33', 'AF': '17', 'BbMxA': '1.62', 'BbAvD': '4.35', 'WHH': '5.5', 'WHA': '1.62', 'PSD': '4.72', 'Date': '03/01/16', 'BbAv>2.5': '1.48', 'BWA': '1.55', 'AR': '1', 'BbMx>2.5': '1.52', 'BWD': '4.2', 'BWH': '6'}, {'FTHG': '2', 'AwayTeam': 'Vallecano', 'HC': '7', 'VCA': '5.75', 'VCD': '4.3', 'HTAG': '1', 'VCH': '1.6', 'HTR': 'A', 'BbAvH': '1.6', 'HomeTeam': 'Valencia', 'PSH': '1.62', 'PSCH': '1.6', 'FTR': 'D', 'BbAHh': '-1', 'BbMxH': '1.65', 'AST': '8', 'HR': '0', 'BbAvAHH': '2.02', 'BbMx<2.5': '2.31', 'LBA': '5.25', 'AC': '9', 'B365A': '5.5', 'PSCD': '4.4', 'AS': '18', 'AY': '3', 'BbMxD': '4.38', 'IWD': '3.9', 'BbMxAHA': '1.88', 'BbAvA': '5.47', 'PSCA': '6.03', 'Div': 'SP1', 'LBH': '1.6', 'IWA': '5', 'Bb1X2': '44', 'BbMxAHH': '2.07', 'HF': '17', 'HST': '5', 'HS': '13', 'WHD': '3.75', 'BbAv<2.5': '2.18', 'LBD': '4', 'PSA': '5.8', 'FTAG': '2', 'BbAH': '28', 'HY': '1', 'B365H': '1.62', 'BbOU': '41', 'IWH': '1.6', 'HTHG': '0', 'BbAvAHA': '1.84', 'B365D': '4', 'AF': '20', 'BbMxA': '5.8', 'BbAvD': '4.05', 'WHH': '1.61', 'WHA': '5.5', 'PSD': '4.33', 'Date': '17/01/16', 'BbAv>2.5': '1.67', 'BWA': '5.25', 'AR': '0', 'BbMx>2.5': '1.75', 'BWD': '4.1', 'BWH': '1.62'}, {'FTHG': '0', 'AwayTeam': 'Sp Gijon', 'HC': '6', 'VCA': '4.8', 'VCD': '4', 'HTAG': '0', 'VCH': '1.75', 'HTR': 'D', 'BbAvH': '1.73', 'HomeTeam': 'Valencia', 'PSH': '1.78', 'PSCH': '1.68', 'FTR': 'A', 'BbAHh': '-1', 'BbMxH': '1.8', 'AST': '3', 'HR': '0', 'BbAvAHH': '2.3', 'BbMx<2.5': '2.04', 'LBA': '4.75', 'AC': '3', 'B365A': '4.75', 'PSCD': '3.9', 'AS': '7', 'AY': '2', 'BbMxD': '4.12', 'IWD': '3.7', 'BbMxAHA': '1.68', 'BbAvA': '4.77', 'PSCA': '5.88', 'Div': 'SP1', 'LBH': '1.73', 'IWA': '4.5', 'Bb1X2': '45', 'BbMxAHH': '2.37', 'HF': '15', 'HST': '3', 'HS': '16', 'WHD': '3.5', 'BbAv<2.5': '1.94', 'LBD': '3.8', 'PSA': '4.79', 'FTAG': '1', 'BbAH': '26', 'HY': '0', 'B365H': '1.75', 'BbOU': '40', 'IWH': '1.7', 'HTHG': '0', 'BbAvAHA': '1.64', 'B365D': '3.75', 'AF': '21', 'BbMxA': '5.15', 'BbAvD': '3.76', 'WHH': '1.75', 'WHA': '5', 'PSD': '4', 'Date': '31/01/16', 'BbAv>2.5': '1.85', 'BWA': '5', 'AR': '0', 'BbMx>2.5': '1.92', 'BWD': '3.6', 'BWH': '1.75'}, {'FTHG': '2', 'AwayTeam': 'Espanol', 'HC': '9', 'VCA': '5', 'VCD': '3.8', 'HTAG': '0', 'VCH': '1.75', 'HTR': 'D', 'BbAvH': '1.74', 'HomeTeam': 'Valencia', 'PSH': '1.77', 'PSCH': '1.69', 'FTR': 'H', 'BbAHh': '-1', 'BbMxH': '1.85', 'AST': '6', 'HR': '0', 'BbAvAHH': '2.37', 'BbMx<2.5': '1.96', 'LBA': '4.75', 'AC': '9', 'B365A': '5', 'PSCD': '3.89', 'AS': '19', 'AY': '3', 'BbMxD': '3.89', 'IWD': '3.45', 'BbMxAHA': '1.66', 'BbAvA': '4.89', 'PSCA': '5.77', 'Div': 'SP1', 'LBH': '1.73', 'IWA': '4', 'Bb1X2': '44', 'BbMxAHH': '2.47', 'HF': '8', 'HST': '4', 'HS': '17', 'WHD': '3.3', 'BbAv<2.5': '1.88', 'LBD': '3.6', 'PSA': '5.26', 'FTAG': '1', 'BbAH': '28', 'HY': '1', 'B365H': '1.75', 'BbOU': '38', 'IWH': '1.85', 'HTHG': '0', 'BbAvAHA': '1.61', 'B365D': '3.6', 'AF': '19', 'BbMxA': '5.26', 'BbAvD': '3.65', 'WHH': '1.8', 'WHA': '5', 'PSD': '3.78', 'Date': '13/02/16', 'BbAv>2.5': '1.91', 'BWA': '4.75', 'AR': '0', 'BbMx>2.5': '2', 'BWD': '3.6', 'BWH': '1.78'}, {'FTHG': '0', 'AwayTeam': 'Ath Bilbao', 'HC': '7', 'VCA': '3.3', 'VCD': '3.4', 'HTAG': '0', 'VCH': '2.3', 'HTR': 'D', 'BbAvH': '2.28', 'HomeTeam': 'Valencia', 'PSH': '2.33', 'PSCH': '2.12', 'FTR': 'A', 'BbAHh': '-0.5', 'BbMxH': '2.38', 'AST': '4', 'HR': '0', 'BbAvAHH': '2.27', 'BbMx<2.5': '1.78', 'LBA': '3.2', 'AC': '7', 'B365A': '3.3', 'PSCD': '3.43', 'AS': '13', 'AY': '0', 'BbMxD': '3.4', 'IWD': '3.2', 'BbMxAHA': '1.72', 'BbAvA': '3.21', 'PSCA': '3.89', 'Div': 'SP1', 'LBH': '2.25', 'IWA': '3.2', 'Bb1X2': '45', 'BbMxAHH': '2.33', 'HF': '9', 'HST': '3', 'HS': '9', 'WHD': '3.25', 'BbAv<2.5': '1.71', 'LBD': '3.3', 'PSA': '3.37', 'FTAG': '3', 'BbAH': '28', 'HY': '2', 'B365H': '2.3', 'BbOU': '39', 'IWH': '2.2', 'HTHG': '0', 'BbAvAHA': '1.66', 'B365D': '3.2', 'AF': '13', 'BbMxA': '3.37', 'BbAvD': '3.28', 'WHH': '2.25', 'WHA': '3.25', 'PSD': '3.4', 'Date': '28/02/16', 'BbAv>2.5': '2.11', 'BWA': '3.3', 'AR': '0', 'BbMx>2.5': '2.21', 'BWD': '3.3', 'BWH': '2.25'}, {'FTHG': '1', 'AwayTeam': 'Ath Madrid', 'HC': '6', 'VCA': '2', 'VCD': '3.3', 'HTAG': '1', 'VCH': '4.4', 'HTR': 'D', 'BbAvH': '4.15', 'HomeTeam': 'Valencia', 'PSH': '4.41', 'PSCH': '4.3', 'FTR': 'A', 'BbAHh': '0.25', 'BbMxH': '4.41', 'AST': '5', 'HR': '1', 'BbAvAHH': '2.21', 'BbMx<2.5': '1.56', 'LBA': '2', 'AC': '7', 'B365A': '2', 'PSCD': '3.23', 'AS': '21', 'AY': '1', 'BbMxD': '3.4', 'IWD': '3.3', 'BbMxAHA': '1.76', 'BbAvA': '1.99', 'PSCA': '2.09', 'Div': 'SP1', 'LBH': '4', 'IWA': '2.1', 'Bb1X2': '45', 'BbMxAHH': '2.27', 'HF': '13', 'HST': '3', 'HS': '10', 'WHD': '3.1', 'BbAv<2.5': '1.51', 'LBD': '3.2', 'PSA': '2.02', 'FTAG': '3', 'BbAH': '28', 'HY': '1', 'B365H': '4', 'BbOU': '33', 'IWH': '3.3', 'HTHG': '1', 'BbAvAHA': '1.71', 'B365D': '3.3', 'AF': '11', 'BbMxA': '2.1', 'BbAvD': '3.23', 'WHH': '4', 'WHA': '2.05', 'PSD': '3.35', 'Date': '06/03/16', 'BbAv>2.5': '2.49', 'BWA': '1.95', 'AR': '0', 'BbMx>2.5': '2.61', 'BWD': '3.3', 'BWH': '3.9'}, {'FTHG': '0', 'AwayTeam': 'Celta', 'HC': '4', 'VCA': '3.13', 'VCD': '3.6', 'HTAG': '0', 'VCH': '2.3', 'HTR': 'D', 'BbAvH': '2.29', 'HomeTeam': 'Valencia', 'PSH': '2.31', 'PSCH': '2.22', 'FTR': 'A', 'BbAHh': '-0.25', 'BbMxH': '2.4', 'AST': '6', 'HR': '0', 'BbAvAHH': '1.98', 'BbMx<2.5': '2.01', 'LBA': '3', 'AC': '5', 'B365A': '3', 'PSCD': '3.56', 'AS': '13', 'AY': '0', 'BbMxD': '3.63', 'IWD': '3.3', 'BbMxAHA': '1.99', 'BbAvA': '3.07', 'PSCA': '3.47', 'Div': 'SP1', 'LBH': '2.25', 'IWA': '3.1', 'Bb1X2': '45', 'BbMxAHH': '2.02', 'HF': '14', 'HST': '4', 'HS': '14', 'WHD': '3.1', 'BbAv<2.5': '1.93', 'LBD': '3.4', 'PSA': '3.2', 'FTAG': '2', 'BbAH': '26', 'HY': '1', 'B365H': '2.3', 'BbOU': '38', 'IWH': '2.2', 'HTHG': '0', 'BbAvAHA': '1.88', 'B365D': '3.5', 'AF': '14', 'BbMxA': '3.2', 'BbAvD': '3.41', 'WHH': '2.4', 'WHA': '3.1', 'PSD': '3.63', 'Date': '20/03/16', 'BbAv>2.5': '1.86', 'BWA': '2.85', 'AR': '0', 'BbMx>2.5': '1.98', 'BWD': '3.4', 'BWH': '2.35'}, {'FTHG': '2', 'AwayTeam': 'Sevilla', 'HC': '10', 'VCA': '3', 'VCD': '3.6', 'HTAG': '0', 'VCH': '2.38', 'HTR': 'H', 'BbAvH': '2.31', 'HomeTeam': 'Valencia', 'PSH': '2.36', 'PSCH': '2.32', 'FTR': 'H', 'BbAHh': '-0.25', 'BbMxH': '2.4', 'AST': '4', 'HR': '0', 'BbAvAHH': '2.01', 'BbMx<2.5': '2.23', 'LBA': '2.9', 'AC': '3', 'B365A': '3.2', 'PSCD': '3.7', 'AS': '7', 'AY': '2', 'BbMxD': '3.67', 'IWD': '3.3', 'BbMxAHA': '1.9', 'BbAvA': '2.97', 'PSCA': '3.14', 'Div': 'SP1', 'LBH': '2.25', 'IWA': '2.75', 'Bb1X2': '45', 'BbMxAHH': '2.1', 'HF': '15', 'HST': '9', 'HS': '23', 'WHD': '3.5', 'BbAv<2.5': '2.09', 'LBD': '3.5', 'PSA': '3.08', 'FTAG': '1', 'BbAH': '28', 'HY': '2', 'B365H': '2.2', 'BbOU': '37', 'IWH': '2.4', 'HTHG': '1', 'BbAvAHA': '1.85', 'B365D': '3.4', 'AF': '18', 'BbMxA': '3.2', 'BbAvD': '3.47', 'WHH': '2.4', 'WHA': '2.8', 'PSD': '3.67', 'Date': '10/04/16', 'BbAv>2.5': '1.72', 'BWA': '3', 'AR': '0', 'BbMx>2.5': '1.83', 'BWD': '3.4', 'BWH': '2.25'}, {'FTHG': '4', 'AwayTeam': 'Eibar', 'HC': '6', 'VCA': '5.4', 'VCD': '4.2', 'HTAG': '0', 'VCH': '1.65', 'HTR': 'H', 'BbAvH': '1.63', 'HomeTeam': 'Valencia', 'PSH': '1.65', 'PSCH': '1.66', 'FTR': 'H', 'BbAHh': '-1', 'BbMxH': '1.67', 'AST': '2', 'HR': '0', 'BbAvAHH': '2.1', 'BbMx<2.5': '2.15', 'LBA': '5.25', 'AC': '3', 'B365A': '5.25', 'PSCD': '4.22', 'AS': '9', 'AY': '2', 'BbMxD': '4.26', 'IWD': '3.6', 'BbMxAHA': '1.81', 'BbAvA': '5.25', 'PSCA': '5.51', 'Div': 'SP1', 'LBH': '1.62', 'IWA': '5.1', 'Bb1X2': '49', 'BbMxAHH': '2.16', 'HF': '10', 'HST': '6', 'HS': '9', 'WHD': '3.8', 'BbAv<2.5': '2.05', 'LBD': '4', 'PSA': '5.58', 'FTAG': '0', 'BbAH': '30', 'HY': '1', 'B365H': '1.62', 'BbOU': '40', 'IWH': '1.65', 'HTHG': '3', 'BbAvAHA': '1.77', 'B365D': '4.2', 'AF': '6', 'BbMxA': '5.58', 'BbAvD': '4.04', 'WHH': '1.67', 'WHA': '5', 'PSD': '4.22', 'Date': '20/04/16', 'BbAv>2.5': '1.75', 'BWA': '5.25', 'AR': '0', 'BbMx>2.5': '1.81', 'BWD': '3.9', 'BWH': '1.6'}, {'FTHG': '0', 'AwayTeam': 'Villarreal', 'HC': '9', 'VCA': '3.5', 'VCD': '3.5', 'HTAG': '2', 'VCH': '2.15', 'HTR': 'A', 'BbAvH': '2.13', 'HomeTeam': 'Valencia', 'PSH': '2.16', 'PSCH': '1.94', 'FTR': 'A', 'BbAHh': '-0.25', 'BbMxH': '2.2', 'AST': '3', 'HR': '0', 'BbAvAHH': '1.83', 'BbMx<2.5': '2.03', 'LBA': '3.5', 'AC': '3', 'B365A': '3.4', 'PSCD': '3.61', 'AS': '8', 'AY': '2', 'BbMxD': '3.56', 'IWD': '3.3', 'BbMxAHA': '2.08', 'BbAvA': '3.43', 'PSCA': '4.39', 'Div': 'SP1', 'LBH': '2.1', 'IWA': '3.6', 'Bb1X2': '44', 'BbMxAHH': '1.88', 'HF': '15', 'HST': '1', 'HS': '7', 'WHD': '3.2', 'BbAv<2.5': '1.95', 'LBD': '3.3', 'PSA': '3.64', 'FTAG': '2', 'BbAH': '29', 'HY': '0', 'B365H': '2.2', 'BbOU': '38', 'IWH': '2', 'HTHG': '0', 'BbAvAHA': '2.03', 'B365D': '3.3', 'AF': '11', 'BbMxA': '3.64', 'BbAvD': '3.42', 'WHH': '2.2', 'WHA': '3.4', 'PSD': '3.53', 'Date': '01/05/16', 'BbAv>2.5': '1.84', 'BWA': '3.4', 'AR': '0', 'BbMx>2.5': '1.95', 'BWD': '3.4', 'BWH': '2.15'}, {'FTHG': '0', 'AwayTeam': 'Sociedad', 'HC': '4', 'VCA': '3.5', 'VCD': '3.9', 'HTAG': '0', 'VCH': '2', 'HTR': 'D', 'BbAvH': '1.98', 'HomeTeam': 'Valencia', 'PSH': '2.06', 'PSCH': '2.08', 'FTR': 'A', 'BbAHh': '-0.5', 'BbMxH': '2.1', 'AST': '7', 'HR': '0', 'BbAvAHH': '2', 'BbMx<2.5': '2.65', 'LBA': '3.5', 'AC': '6', 'B365A': '3.75', 'PSCD': '3.76', 'AS': '14', 'AY': '2', 'BbMxD': '3.9', 'IWD': '3.7', 'BbMxAHA': '1.91', 'BbAvA': '3.63', 'PSCA': '3.65', 'Div': 'SP1', 'LBH': '1.95', 'IWA': '3.9', 'Bb1X2': '50', 'BbMxAHH': '2.06', 'HF': '17', 'HST': '0', 'HS': '8', 'WHD': '3.75', 'BbAv<2.5': '2.32', 'LBD': '3.6', 'PSA': '3.63', 'FTAG': '1', 'BbAH': '29', 'HY': '2', 'B365H': '1.95', 'BbOU': '37', 'IWH': '1.8', 'HTHG': '0', 'BbAvAHA': '1.87', 'B365D': '3.75', 'AF': '12', 'BbMxA': '3.9', 'BbAvD': '3.71', 'WHH': '1.91', 'WHA': '3.3', 'PSD': '3.84', 'Date': '13/05/16', 'BbAv>2.5': '1.58', 'BWA': '3.75', 'AR': '0', 'BbMx>2.5': '1.64', 'BWD': '3.7', 'BWH': '1.95'}]
[] [] []
正如你所看到的,在最后3个函数调用中没有收集任何东西,而我的'printf debugging'(在if之前和之后插入print(行))表明在那些调用'copy'变量中似乎没有要翻转的项目。
答案 0 :(得分:3)
首次在for
循环中迭代CSV阅读器时,它将使用迭代器协议读取文件。见https://docs.python.org/2/glossary.html#term-iterator
此迭代器协议保持迭代器的状态。因此,当您到达文件的末尾时(在第一个for循环的末尾),将没有更多的条目迭代到另一个for循环。
换句话说:对迭代器进行第二次迭代不会“倒回”迭代器,它将在第一次迭代停止的地方开始。
答案 1 :(得分:3)
csv.DictReader
可能是一个迭代器。当它到达要迭代的数据的末尾时,它没有什么可以迭代的。
如果您不得不多次迭代数据,则应将值存储到集合中。
copy = list(csv.DictReader(database))
之类的东西可以解决问题。