Issue
I am going through dataquest courses with this particular one using python/jupyter notebook Here is the main part of the code I am struggling with:
index = 0
for row in data:
data[index] = row[:-1]
index += 1
panda and re were imported via a helper.py
I am mainly unsure of the purpose of making data[index] = row[-1] but any help would be appreciated
Solution
It is not easy to answer this question without knowing the structure of data
. I assume that data
is a nested list. The code then causes the last element in each sublist of data to be removed.
Example:
data = [[1,2],[3,4],[5,6],[7,8]]
index = 0
for row in data:
data[index] = row[:-1]
index += 1
print(data)
Output:
[[1], [3], [5], [7]]
I don't know what the bigger picture is, so I can't comment on the use of this action.
Answered By - Jan Schmidt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.