Functions: Intermediate, 6th chapter



  1. header = all_data[1] instead of header = all_data[0]?

  2. apps_data = all_data[0] instead of apps_data = all_data[1:]?

When I write: all_data[0] I receive all data, but when all_data[1] I receive only the header. I have no idea why.

Hi @tomasz.markielow, in the open_dataset() function definition, data[0] fetches the header of the ‘AppleStore.csv’ dataset, whereas data[1:] fetches the rest of the data excluding the header.

Your return output if header is True is a tuple of 2 values: the first (at index 0) being all the data excluding the header, i.e. data[1:], and the second value (at index 1) being the header, i.e., data[0]. So you are returning all the data before you return the header. Swap the positions of the return values as below:


Then all_data[0] will return header, whereas all_data[1] will output all the data as list of lists.

Let’s know if this helps!


This is because in this case the header = True:

The if clause tells the function to return two values:

all_data = data[1:], data[0]


all_data[0] = data[1:]
all_data[1] = data[0]


By default open_dataset has file_name='AppleStore.csv and header=True, if the header is True, the function will return a tuple,( the rest of the data and the head respectively). therefore calling the function, the item in index 0 will be the data, and the item in index 1 will be the header.


Thank you guys! It’s so obvious that I feel embarrassed right now :slight_smile: Thank you once again!

1 Like

Glad we could assist. What causes embarrassment? We are all here to learn and provide assistance where necessary. Always reach out to the community for help/assistance.

1 Like