How to ignore the first line of data when processing CSV data?

前端 未结 17 2204
庸人自扰
庸人自扰 2020-11-22 10:05

I am asking Python to print the minimum number from a column of CSV data, but the top row is the column number, and I don\'t want Python to take the top row into account. Ho

17条回答
  •  一向
    一向 (楼主)
    2020-11-22 10:32

    Python 2.x

    csvreader.next()

    Return the next row of the reader’s iterable object as a list, parsed according to the current dialect.

    csv_data = csv.reader(open('sample.csv'))
    csv_data.next() # skip first row
    for row in csv_data:
        print(row) # should print second row
    

    Python 3.x

    csvreader.__next__()

    Return the next row of the reader’s iterable object as a list (if the object was returned from reader()) or a dict (if it is a DictReader instance), parsed according to the current dialect. Usually you should call this as next(reader).

    csv_data = csv.reader(open('sample.csv'))
    csv_data.__next__() # skip first row
    for row in csv_data:
        print(row) # should print second row
    

提交回复
热议问题