python跳过前几行读取csv,python - 跳过CSV文件的顶部行

I have a collection of csv files generated from a third party application. At the top of each file it has a title, blank line, X lines about the content, blank line, and then the rest is the actual csv.

Since the number of lines is variable I can just skip X lines. I am currently skipping the lines by using a split and getting the number of columns, but I'm sure there is a better way.

can I do this with csvreader or pandas?

# current code

for line in greport.data.splitlines():

# split up the line to work with the fields

fields = line.rstrip().rstrip(',').split(',')

if len(fields) < 5:

continue

else:

#

# sample file

Title of report

Server Name: all

Group Name: all

Client Name: all

Save Set Name: all

Status: all

Backup Type: all

Level: all

Group Start Time: from 11/11/14 6:00:00 PM to 11/12/14 5:59:00 PM

Client Name,Save Set Name,Save Set ID,Group Start Time,Save Type,Level,Status

server1,All,,11/11/14 6:00:00 PM,save,skip,succeeded,

server2,All,,11/11/14 6:00:00 PM,save,skip,succeeded,

server3,All,,11/12/14 12:00:00 AM,save,skip,succeeded,

server4,ASR:\,3630378478,11/11/14 11:00:00 PM,save,1,succeeded,

解决方案

Yes, you can achieve the same effect with csv:

import csv

with open('data', 'r') as f:

reader = csv.reader(f)

for row in reader:

if len(row) < 5:

continue

#process the data

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值