List index out of list Python CSV files

Question:

so im learning some python but i got a list out of index error at this point if i put my header index to 0 it works not the way i see it works but ok, but if i get an upper index for header it wont can you help me out why?photo of my csv file

[heres the first picture of my code]and 2nd pic3

Asked By: Phenex

||

Answers:

When you put your header index as 0 what is output?

Assuming your delimiter is tab

with open("sample.csv", "r") as csvfile:
   reader = csv.reader(csvfile,delimiter='t')
   headers = next(reader, None)
   print(headers[1])

Answered By: Jebaseelan Ravi

My delimeter was t after i changed it to it problem all solved

Answered By: Phenex
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.