1

处理可以帮助我自动为游戏评分的 NFL CSV 文件。现在,我只能将球队和分数上传到 csv 文件的 1 列中。

这些都在 A 栏中

示例:A

1   NYJ
2   27
3   PHI
4   20
5   BUF
6   13
7   DET
8   35
9   CIN
10  27
11  IND
12  10
13  MIA
14  24
15  NO
16  21

或者

[['NYJ`'], ['27'], ['PHI'], ['20'], ['BUF'], ['13'], ['DET'], ['35'], ['CIN'], ['27'], ['IND'], ['10'], ['MIA'], ['24'], ['NO'], ['21'], ['TB'], ['12'], ['WAS'], ['30'], ['CAR'], ['25'], ['PIT'], ['10'], ['ATL'], ['16'], ['JAC'], ['20'], ['NE'], ['28'], ['NYG'], ['20'], ['MIN'], ['24'], ['TEN'], ['23'], ['STL'], ['24'], ['BAL'], ['21'], ['CHI'], ['16'], ['CLE'], ['18'], ['KC'], ['30'], ['GB'], ['8'], ['DAL'], ['6'], ['HOU'], ['24'], ['DEN'], ['24'], ['ARI'], ['32'], ['SD'], ['6'`], ['SF'], ['41'], ['SEA'], ['22'], ['OAK'], ['6']]

我想要的是这样的:

   A  B   C  D
1 NYJ 27 PHI 20
2 BUF 13 DET 35
3 CIN 27 IND 10
4 MIA 24 NO  21

我已经阅读了以前关于此的文章,但还没有开始工作。对此有什么想法吗?

任何帮助表示赞赏和感谢!

当前脚本:

import nflgame
import csv
print "Purpose of this script is to get NFL Scores to help out with GUT"

pregames = nflgame.games(2013, week=[4], kind='PRE')

out = open("scores.csv", "wb")
output = csv.writer(out)

for score in pregames:
    output.writerows([[score.home],[score.score_home],[score.away],[score.score_away]])
4

2 回答 2

1

您目前正在使用.writerows()写入 4 行,每行有一列。

相反,你想要:

output.writerow([score.home, score.score_home, score.away, score.score_away])

写一行 4 列。

于 2013-09-03T20:16:39.720 回答
0

在不知道分数数据的情况下,尝试将 writerows 更改为 writerow:

import nflgame
import csv
print "Purpose of this script is to get NFL Scores to help out with GUT"

pregames = nflgame.games(2013, week=[4], kind='PRE')

out = open("scores.csv", "wb")
output = csv.writer(out)

for score in pregames:
    output.writerow([[score.home],[score.score_home],[score.away],[score.score_away]])

这将在一行中全部输出。

于 2013-09-03T20:16:55.197 回答