Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

865
Vistas
Python - Skip header row with csv.reader

I tried this proposed solution on a large (7000 line) csv file): Read File From Line 2 or Skip Header Row`

The following code worked but only if I manually remove the header:

RatedTracksFile = open('pyall_rated.csv')
RatedTracksReader = csv.reader(RatedTracksFile)
data_list = list(csv.reader(RatedTracksFile))
eligible1 = open('py_all1.csv', 'a') # open py_all1.csv in append mode
for i in range(len(data_list)):
    trackrating = int(data_list[i][12])
    ...

I tried different ways of adding this suggested code:

with open(fname) as f:
    next(f)
    for line in f:

I am new to python and cannot figure out how to add that in. I keep getting the same value type error since it still reads row 1,col 12 (which is a string from the header) and not the integer found on row 2, col 12:

ValueError: invalid literal for int() with base 10: 'GroupDesc'

SOLVED: Based on Sphinx' comment below (thanks!).

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

import csv
with open("1800.csv", "rb") as files:
   reader = csv.reader(files)
   next(reader, None)
   for data in reader:
      print data

This is working for me, try this.

over 4 years ago · Santiago Trujillo Denunciar

0

If your header contains your column names, the nicest solution is to use csv.DictReader

>>> import csv
>>> with open('names.csv') as csvfile:
...     reader = csv.DictReader(csvfile)
...     for row in reader:
...         print(row['first_name'], row['last_name'])
...
Baked Beans
Lovely Spam
Wonderful Spam
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda