Python CSV删除特定行

2022-08-06

以下示例是关于Python中包含Python CSV删除特定行用法的示例代码,想了解Python CSV删除特定行的具体用法?Python CSV删除特定行怎么用?Python CSV删除特定行使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:python csv delete specific row源码类型:Python
lines = list()
memberName = input("Please enter a member's name to be deleted.")
with open('mycsv.csv', 'r') as readFile:
    reader = csv.reader(readFile)
    for row in reader:
        lines.append(row)
        for field in row:
            if field == memberName:
                lines.remove(row)

with open('mycsv.csv', 'w') as writeFile:
    writer = csv.writer(writeFile)
    writer.writerows(lines)

本文地址:https://www.itbaoku.cn/snippets/795563.html