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

前端 未结 17 1995
庸人自扰
庸人自扰 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:20

    In a similar use case I had to skip annoying lines before the line with my actual column names. This solution worked nicely. Read the file first, then pass the list to csv.DictReader.

    with open('all16.csv') as tmp:
        # Skip first line (if any)
        next(tmp, None)
    
        # {line_num: row}
        data = dict(enumerate(csv.DictReader(tmp)))
    

提交回复
热议问题