''' Purpose: practice analyzing data from a useful dataset ''' # import helpful library to stream dataset aquisition import url ########## get the dataset to be analyzed ########## # specify data source DATASET_SOURCE = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/best-sellers.csv' # get data for the dataset dataset = url.get_dataset( DATASET_SOURCE ) # this function does a lot of behind the scene steps # determine dataset header and data header = dataset[ 0 ] # accesses the first line in the text books = dataset[ 1 : ] # we use the subscripting brackets when we know what indexes we want # determine number of books nbr_books = len( books ) ########## assist the user ########## # get the user's interest in the dataset reply = input( 'Enter interest: ' ) # These two steps clean up the user reply so that it is standard to our data reply = reply.strip() label = reply.capitalize() # determine the column for that label column_index = header.index( label ) # will hand back the column with the specified label; the .index() function finds the index # we may not know # print( column_index ) # get the dataset elements for that column for b in books: # b represents a single book in the list of books # print( b ) cell = b[ column_index ] # this accesses a specific element of an individual book we want print( cell )