I'm looking for the Python equivalent of Swift's count method. array.count.
If the dataset has 9,000 data points I want to be able to find the average rating by dividing by the number of items (rows). Naturally I want to divide by items.count. How is this done in Python?
I know Python also has enumerate with a counter variable like idx. You can then use idx count value for other things like boolean tests.
In Swift we can easily do what I'm trying to do just by using dot syntax and the count method but I cannot figure it out in Python.
If the dataset has 9,000 data points I want to be able to find the average rating by dividing by the number of items (rows). Naturally I want to divide by items.count. How is this done in Python?
Code:
row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['WeChat', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Line', 0.0, 'USD', 1724546, 4.5]
row_5 = ['WhatsApp', 0.0, 'USD', 1126879, 4.0]
app_data_set = [row_1, row_2, row_3, row_4, row_5]
rating_sum = 0
for item in app_data_set:
rating = item[-1]
rating_sum += rating
items_count = item[-1].count() // python doesn't like this nor does it like count(item[-1])
average_rating = rating_sum / items_count
print(average_rating)
I know Python also has enumerate with a counter variable like idx. You can then use idx count value for other things like boolean tests.
Code:
for idx, item in enumerate(app_data_set):
In Swift we can easily do what I'm trying to do just by using dot syntax and the count method but I cannot figure it out in Python.