我在用Python将csv文件中的特定数据读入列表时遇到了一些问题。下面是我的csv文件的一个示例:
Round 1
Player1 Score Player2 Score
P1 5 P2 3
P3 2 P4 4
Round 2
Player1 Score Player2 Score
P1 3 P4 6
Round 3...
(第一轮和第二轮的单元格在顶部合并)
我可以将这个csv文件中的所有数据添加到一个列表中,但是我想忽略包含“第1轮”的行和它下面包含“Player1”、“Score”等的行,只添加数据。“第二轮”行和下面的行也是如此。所需的列表将类似于:[[P1,5,P2,3][P3,2,P4,4][P1,3,P4,6]]。下面是我的代码示例:
playerScores = []
with open(scoreFile) as scores
for row in csv.reader(scores)
playerScores.append(row)
任何帮助,这将是非常感谢,因为我正在挣扎(PS我试图使用“下一个(记分文件)”,但它只是摆脱了标题“第一轮”为我)
干杯
从第二轮开始
您可以添加一个新标志
later_rounds
:或者可以跳过另一个循环的开头:
那么简单的
if
条件呢?你知道吗相关问题 更多 >
编程相关推荐