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

标签 python csv

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

最佳答案

您可以将 csv 阅读器对象转换为列表列表...行存储在列表中,该列表包含列列表。

所以:

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

关于python - 如何在 Python CSV 模块中查找特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30713181/

相关文章:

java - 在 UTF-8 中打开 BufferedReader

python - DictReader 字段名与 csv 阅读器第一行

csv - 使用executescript处理器更新csv值在apache-nifi中使用groovy失败

python - AWS Lambda 压缩文件命令

python - 如何从 urllib 中读取 lines()

php - 将 csv 文件导入数据库 - 带逗号的值

python - 在 Pandas DataFrame 中拆分列表

Python/SQLite - 尽管超时时间长,但数据库仍被锁定

python字典理解迭代器

python - graphviz分割错误