I tried to create another solution, but I’ve failed.
What is the mistake?
I understand the error message, but data_set[index] is a string, not a list. Am I right?
I tried to create another solution, but I’ve failed.
What is the mistake?
I understand the error message, but data_set[index] is a string, not a list. Am I right?
Here we are supposed to find mean of the price
column.
In your code, the value of data_set[index]
is
['284035177', 'Pandora - Music & Radio', '130242560', 'USD', '0.0', '1126879', '3594', '4.0', '4.5', '8.4.1', '12+', 'Music', '37', '4', '1', '1']
which is the 5th row in data_set
.
Again, you’re not using the iteration variable value
inside the for loop.
The correct code should have been
def mean(data_set, index):
lst = []
# print(data_set[index])
for row in data_set:
lst.append(float(row[index]))
add = sum(lst)
length = len(lst)
return add/length
Thanks a lot for the clarification, so I should have type ( row ) instead of ( value ), am I right?
You should use the iteration variable in there. My iteration variable is row
, and yours is value
.
for value in data_set:
lst.append(float(value[index]))
Oh yes, tanks a lot.