Replace this line with the output/error
avg_rating is less than what we expected.
<!--Dividing the rating_sum and app_data(excluding header row) to find avg_rating.
Here, I thought dividing using len() function or number of rows(7,197) will give same results. But I am getting the error that the avg_rating is less. where am i going wrong? Guide me pls : -->
I would highly recommend that you go through the content on lists and list indexing/slicing again. Because it doesn’t seem you have reached a level of intuitive understanding of that concept. Which is perfectly ok, you just need to review it a bit more.
There are a couple of issues in your code.
Firstly, you keep slicing apps_data.
apps_data = apps_data[1:]
for row in apps_data[1:]:
avg_rating = rating_sum / len(apps_data[1:])
If I gave you the list what would be the output of the following:
a = [1, 2, 3, 4]
a= a[1:]
a= a[1:]
print(a)
Think about the above and think more about how (and why) you are using apps_data[1:] in your code.
Secondly, the following
float(row[1:][7])
Print out a single row, then
print out row[1:], and then
print out row[1:][7].
Do you get the value you need? Cross-check with the data and see if it matches up or not. Think about what each step above is doing and how you are slicing and indexing the list.
To exclude the header, app_data is stored as app_data[1:].
apps_data = **apps_data[1:]**--> to define it
for row in **apps_data[1:]**:---> for loop
avg_rating = rating_sum / len**(apps_data[1:]**) for finding avg_rating using len() ==> this is how i understood abt app_data[1:] at each time it is used.
the example you have mentioned:
a = [1, 2, 3, 4]
a= a[1:]
a= a[1:]
print(a)
expected
<<<[2, 3, 4]>>>
actual
<<<[3, 4]>>> why??
It's a good suggestion about going through indexing/slicing topic again to know how slicing varies at each step. Really, appreciate your time for replying.