Can't understand the use of index

could not understand the use of "index " here in first guided project please help

index=0
for row in data:
    data[index]=row[:-1]
    index += 1
    print(data[:3])

The dataset contained a column with a bunch of information about each helicopter escape. This column is lengthy, messy and it doesn’t really add anything from a data perspective.

The loop you’ve attached removes the last column.

This line:

data[index]=row[:-1]

takes all of the information except for whatever was in the last column and stores it back into the dataset in the same row where it was originally.

The index variable allows you to iterate over the dataset to replace each row.

Hope this helps!

1 Like