31 Years of Python | 48 Hour Sale Extension!!!
days
hours
minutes
seconds

Course's first guided project: Profitable Apps - Stuck at exploring function call

Screen Link:
https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/1/analyzing-mobile-app-data

My Code:

‘’’ [1] def open_dataset(dataset_file, keep_header=False):
from csv import reader
opened_file = open(dataset_file)
read_file = reader(opened_file)
opened_dataset = list(read_file)
return opened_dataset

[2] Apple_Store_Dataset = open_dataset(‘AppleStore.csv’)
Google_Play_Dataset = open_dataset(‘googleplaystore.csv’)

[3] def explore_data(dataset, start, end, rows_and_columns=False):
data_slice = dataset[start, end]
for row in data_slice:
print(row)
print(’\n’)
if rows_and_columns:
print((‘Number of rows:’), len(data_slice))
print((‘Number of columns:’), len(data_slice[0]))

[4 ]explore_data(Apple_Store_Dataset, 3, 6, True)’’’

What I expected to happen:
To be able to explore the AppleStore dataset

What actually happened:

TypeErrorTraceback (most recent call last)
<ipython-input-4-d5c57f7fe476> in <module>()
----> 1 explore_data(Apple_Store_Dataset, 3, 6, True)

<ipython-input-3-f0b27404f6cb> in explore_data(dataset, start, end, rows_and_columns)
      1 def explore_data(dataset, start, end, rows_and_columns=False):
----> 2     data_slice = dataset[start, end]
      3     for row in data_slice:
      4         print(row)
      5         print('\n')

TypeError: list indices must be integers, not tuple

Not sure how the list indices are not integers, when I called the function explore_data, I entered in the parameters the following arguments: Apple_Store_Dataset, 3, 6, True
When I defined the function, I made the 2nd and 3rd parameters the list indices for the data set slice.

@KevinLuigiReyes, welcome to the community!

Your error is here data_slice = dataset[start, end]

To slice the dataset list, it should be data_slice = dataset[start:end]

I hope this helps.

1 Like

@KevinLuigiReyes,

To debug your code next time, check the error message, the error message for your block of code is: TypeError: list indices must be integers, not tuple which means that you used the tuple datatype as the index for a list in your code block instead of the correct data type which is the integer datatype.

The tuple you used to slice the list is start,end instead of slicing the list using start: end.

Hence, your code block in [3] will be:

def explore_data(dataset, start, end, rows_and_columns=False):
    data_slice = dataset[start: end]
    for row in data_slice:
        print(row)
        print('\n')
    if rows_and_columns:
        print(('Number of rows:'), len(data_slice))
        print(('Number of columns:'), len(data_slice[0]))

I hope this helps.

1 Like

Yeah, wow, that makes sense lol, simple error, probably gonna be more in programming lol.

Thank you so much! :slight_smile:

I am glad I could be of help.

Good luck and Happy learning!