小编deb*_*ged的帖子

从CSV中删除空白行?

我有一个大的csv文件,其中一些行是完全空白的.如何使用Python删除csv中的所有空行?

在你提出所有建议后,这就是我到目前为止所做的

import csv

# open input csv for reading
inputCSV = open(r'C:\input.csv', 'rb')

# create output csv for writing
outputCSV = open(r'C:\OUTPUT.csv', 'wb')

# prepare output csv for appending
appendCSV = open(r'C:\OUTPUT.csv', 'ab')

# create reader object
cr = csv.reader(inputCSV, dialect = 'excel')

# create writer object
cw = csv.writer(outputCSV, dialect = 'excel')

# create writer object for append
ca = csv.writer(appendCSV, dialect = 'excel')

# add pre-defined fields
cw.writerow(['FIELD1_','FIELD2_','FIELD3_','FIELD4_'])

# delete existing field names in input CSV
# …
Run Code Online (Sandbox Code Playgroud)

python csv delete-row

17
推荐指数
4
解决办法
5万
查看次数

标签 统计

csv ×1

delete-row ×1

python ×1