Jimmy_Jump
Jimmy_Jump

Reputation: 27

Skipping the first list of a list

I have imported an excel file.

I have stripped out the white space and split the data to make a list of list.

for i in range(len(Data)):
  Data[i] = sData[i].strip().split(',')

Now I want to convert the 2nd element in every list to an integer.

Except the first line of code Data[0] are the titles from excel.

Which obviously cannot be converted to an int.

How do I skip over the first list Data[0] to convert the 2nd element Data[1][1] in the following lists?

I thought it would be something like this:

Data[i][0:] = int(Data[i][1])

But I am wrong. Any advice?

Upvotes: 0

Views: 48

Answers (1)

superb rain
superb rain

Reputation: 5531

Process the rows after the first?

for row in Data[1:]:
  row[1] = int(row[1])

Or do it in your existing loop:

  if i:
    Data[i][1] = int(Data[i][1])

Upvotes: 1

Related Questions