Since the rating_data variables are all lists, we’re accessing the item in the 2nd index of each list in order to calculate the average rating. In the fb_rating_data list, the item at index 2 is row_1[-1], which is the last item in row_1: 3.5. So fb_rating_data[2] is 3.5. If you follow the same reasoning with the other 2 rating_data variables, you find that insta_rating_data[2] is 4.5 and pandora_rating_data[2] is 4.0. These are the 3 numbers being averaged for avg_rating.
Here’s your row_1: row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5] which is a python list (indicated by [])
In a Python list, the elements (items present in the list) are 0 indexed and can be selected as list_name[index number]
Here’s how it can be visualized:
So when you write row_1[0], what you are saying is select the 0th index element in row_1 which in this case is 'Facebook'
Now, coming to your question: avg_rating = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2]) / 3