如何在 Python CSV 模块中查找特定行

Sam*_*Sam 3 python csv

我需要找到从第 4 列到 CSV 文件末尾的第三行。我该怎么做?我知道我可以从第 4 列中找到第 [3] 行的值,但是我如何获得第三行?

MrA*_*ley 6

您可以将 csv reader 对象转换为列表列表......行存储在一个列表中,该列表包含列的列表。

所以:

csvr = csv.reader(file)
csvr = list(csvr)
csvr[2]     # The 3rd row
csvr[2][3]  # The 4th column on the 3rd row.
csvr[-4][-3]# The 3rd column from the right on the 4th row from the end
Run Code Online (Sandbox Code Playgroud)