gpt4 book ai didi

python - 将 CSV 文件 1 列操作为多个 - NFL 分数

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:51 25 4
gpt4 key购买 nike

正在处理 NFL CSV 文件,该文件可以帮助我自动为比赛评分。现在,我可以将团队和分数上传到 csv 文件的仅 1 列中。

这些都在 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]])

最佳答案

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

相反,您想要:

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

写入 4 列的单行。

关于python - 将 CSV 文件 1 列操作为多个 - NFL 分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com