【发布时间】:2018-01-08 21:47:06
【问题描述】:
到目前为止,这是我的代码,我想保留 CSV 中的许多行,但如果是第 3 行,则忽略
如果不是第三行,我想省略这行:
Curriculum Name,,Organization Employee Number,Employee Department,Employee Name,Employee Email,Employee Status,Date Assigned,Completion Date,Completion Status,Manager Name,Manager Email
它每 10 行左右出现一次,但如果它不是第一行(总是第三行),我希望将其删除
import csv, sys, os
#Read the CSV file and skipping the first 130 lines based on mylist
scanReport = open('Audit.csv', 'r')
scanReader = csv.reader(scanReport)
#search row's in csv - print out list
for file in glob.glob(r'C:\sans\Audit.csv'):
lineNumber = 0
str - "Curriculum Name"
with open('first.csv', 'rb') as inp, open('first_edit.csv', 'wb') as out:
writer = csv.writer(out)
for row in csv.writer(inp):
if row[2] != " 0":
writer.writerow(row)
【问题讨论】:
-
你可能想问一个问题,因为目前我投票结束这个问题,因为不清楚这个问题可能是什么。不过,请务必查看网站指南如何提出好的问题!
标签: python python-3.x csv