我有 3 个不同的文件:NewRush4.csv、NewRush5.csv、NewRush6.csv。我正在尝试从每个赛季(第 4、5 和 6 季)中收集“历史领袖”。
我想读取每个文件中每个玩家的名字,如果它们是重复的,则将它们组合起来,或者读取第一个文件并将其与其他两个文件进行比较以组合它们。
这是我的python代码。我必须阅读第一个文件。我不确定如何使用 DictReader。
#!/usr/bin/python
import csv
file = open("NewRush4.csv", "rb")
for line in csv.DictReader(file, delimiter=","):
name = line["Player"].strip()
yds = line["YDS"].strip()
car = line["CAR"].strip()
td = line["TD"].strip()
fum = line["FUM"].strip()
ypc = line["YPC"].strip()
print "%-20s%10s%10s%10s%10s%10s" % (name, car, yds, td, fum, ypc)
file.close()
输出:
49erswag 3 14.0 0 0 4.7
A Beast Playa 7 23.0 0 0 3.3
A Swanky Guy 2 29 154.0 1 2 5.3
ACIDRUST 1 4.0 0 0 4.0
Aj dahitman 227 1898.0 19 2 8.4
Aldizzl 10 45.0 0 0 4.5
Areis21 13 58.0 0 2 4.5
at43 48 214.0 1 1 4.5
Ayala2012xTCU 57 195.0 0 1 3.4
B O R Nx 25 13 31.0 0 1 2.4
B r e e z yx60 4 13.0 0 0 3.3
Beardown74 116 621.0 6 3 5.4
beatdown54 2010 26 126.0 3 1 4.8
behe SWAG 1 -5.0 0 0 -5.0
Big Murph22 73 480.0 6 2 6.6
BigBlack973 18 57.0 0 1 3.2
BiGDaDDyNaPSacK 184 1181.0 20 4 6.4
第 4 季文件:
Player,YDS,TD,CAR,FUM,YPC
49erswag, 14.0, 0, 3, 0, 4.7
A Beast Playa, 23.0, 0, 7, 0, 3.3
A Swanky Guy 2, 154.0, 1, 29, 2, 5.3
ACIDRUST, 4.0, 0, 1, 0, 4.0
Aj dahitman, 1898.0, 19, 227, 2, 8.4
Aldizzl, 45.0, 0, 10, 0, 4.5
Areis21, 58.0, 0, 13, 2, 4.5
at43, 214.0, 1, 48, 1, 4.5
Ayala2012xTCU, 195.0, 0, 57, 1, 3.4
B O R Nx 25, 31.0, 0, 13, 1, 2.4
B r e e z yx60, 13.0, 0, 4, 0, 3.3
...
第 5 季文件:
Player,YDS,TD,CAR,FUM,YPC
a toxic taz, 307.0, 4, 44, 0, 7.0
AbNL Boss, 509.0, 4, 174, 2, 2.9
AFFISHAUL, 190.0, 0, 35, 2, 5.4
AJ DA HITMAN, 1283.0, 19, 228, 6, 5.6
allen5422, 112.0, 2, 18, 0, 6.2
Allxdayxapx, 264.0, 1, 76, 2, 3.5
AlpHaaNike, 51.0, 1, 10, 1, 5.1
Aura Reflexx, 215.0, 1, 40, 0, 5.4
AWAKEN DA BEAST, -5.0, 0, 4, 1, -1.3
AxDub24, -3.0, 0, 2, 1, -1.5
Ayala2012xTCU, 568.0, 4, 173, 1, 3.3
BALLxXHAWKXx, 221.0, 1, 47, 2, 4.7
BANG FIGHTY007, 983.0, 6, 171, 3, 5.7
bang z ro, 29.0, 0, 9, 0, 3.2
BEARDOWN74, 567.0, 6, 104, 2, 5.5
...
因此,如果一名球员打了多个赛季,请添加他的统计数据并打印出来。否则,只需打印。