Screen Link:
https://app.dataquest.io/m/316/functions%3A-intermediate/5/multiple-return-statements
My Code:
def open_dataset(file_name='AppleStore.csv', row0='str'):
opened_file = open(file_name)
from csv import reader
read_file = reader(opened_file)
data = list(read_file)
if row0:
return data[1:]
return data[0:]
apps_data = open_dataset()
print(apps_data[0:1])
The code I used here works, but I want to fully understand why it works and how it differs from the correct answer provided in the lesson.
How would this function determine if there is a header row using only the argument header=True? Isn’t the header row by definition the first row in the dataset? if so, don’t we need to know what kind of data type is actually in the first row to determine if it is indeed a header row (i.e. ‘strings’) vs the first row of data (i.e. ‘int’ or ‘float’)? How does the argument “header=True” determine whether or not the first row contains strings/column labels or just numbers? Every dataset has to have a something in the first row, so how can “header=True” ever identify a dataset without a header row??
I understand that a dataset could ultimately contain any kind of data type, so what makes the Header row unique from all the other rows in the dataset such that I can use a function to identify this uniqueness?