Exercise

Preparing data for market basket analysis

Throughout this course, you will typically encounter data in one of two formats: a pandas DataFrame or a list of lists. DataFrame objects will be constructed by importing a csv file using pandas. They will consist of a single column of data, where each element contains a string of items in a transaction, separated by a comma, as in the table below.

In this exercise, you will practice loading the data from a csv file and will prepare it for use as a list of lists. Note that the path to the grocery store dataset has been defined and is available to you as groceries_path.

Transaction
'milk,bread,biscuit'
'bread,milk,biscuit,cereal'
…
'tea,milk,coffee,cereal'

Instructions

100 XP
  • Import the pandas package under the alias pd.
  • Use pandas to read the csv file at the path specified by groceries_path.
  • Select the Transaction column from the DataFrame and split each string of comma-separated items into a list.
  • Convert the DataFrame of transactions into a list of lists.