Python跳过使用CSV文件的循环中的第一行(字段)? [英] Python skip First line(field) in loop using CSV file?
本文介绍了Python跳过使用CSV文件的循环中的第一行(字段)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用python打开CSV文件。我使用公式循环,但我需要跳过第一行,因为它有头。
I am using python to open CSV file. I am using formula loop but I need to skip the first row because it has header.
到目前为止,我记得是这样的,但它缺少一些东西:我想知道有人知道这个代码我想使用。
So far I remember was something like this but it is missing something: I wonder if someone know this code what I am trying to use.
For row in kidfile:
if row.firstline = false <====== Something is missing here.
continue
if ......
推荐答案
可能你想要的东西:
Probably you want something like:
firstline = True
for row in kidfile:
if firstline: #skip first line
firstline = False
continue
# parse the line
另一种获得相同结果的方法是在循环之前调用 readline
:
An other way to achive the same result is calling readline
before the loop:
kidfile.readline() # skip the first line
for row in kidfile:
#parse the line
这篇关于Python跳过使用CSV文件的循环中的第一行(字段)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文