Statement of Completion#ebd22d39
Intro to Pandas for Data Analysis
easy
Exploring Pandas with a Bakery Transaction Dataset
Resolution
Activities
Project.ipynb
Exploring Pandas with The Bread Basket¶
In [18]:
# Begin by importing the libraries
import numpy as np
import pandas as pd
Conceptual Questions¶
1. What is pandas ?¶
In [14]:
# what is pandas ?
Cell In[14], line 2 A data manipulation and analysis library. ^ SyntaxError: invalid syntax
2. What are the two main types of data structure in pandas?¶
In [ ]:
# What are the two main types of data structure in Pandas?
3. Which of the following is NOT
a method for reading data into pandas?¶
In [ ]:
# Which of the following is NOT a method for reading data into pandas?
4. Which function is used to create a pandas DataFrame from a dictionary?¶
In [ ]:
# Which function is used to create a pandas DataFrame from a dictionary?
5. Which function is used to load CSV files in pandas?¶
In [ ]:
# Which function is used to load CSV files in pandas?
6. Which of these methods can display the first five rows of a DataFrame?¶
In [ ]:
# Which of these methods can display the first few rows of a DataFrame?
Working with Dataset¶
7. Load the dataset¶
In [6]:
import pandas as pd
df_data = pd.read_csv('bread-basket.csv')
8. Display the Last 10 Rows¶
In [8]:
last_ten = df_data.tail(10)
9. How to find out the data type of Transaction
column?¶
In [9]:
# Checking the Data Types
df_data['Transaction'].dtype
Out[9]:
dtype('int64')
10. What does the following code do?¶
In [ ]:
# What does the following code do?
11. Which of the following is the correct syntax to get a summary of non-null values and data types for each column in a DataFrame df
?¶
In [19]:
# Which of the following is the correct syntax to get a summary of non-null values and data types for each column in a DataFrame df?
import pandas as pd
df = pd.read_csv('bread-basket.csv')
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 20507 entries, 0 to 20506 Data columns (total 5 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Transaction 20507 non-null int64 1 Item 20507 non-null object 2 date_time 20507 non-null object 3 period_day 20507 non-null object 4 weekday_weekend 20507 non-null object dtypes: int64(1), object(4) memory usage: 801.2+ KB
12. Which of the following is the correct way to view the unique items bought in the Item
column?¶
In [11]:
# Which of the following is the correct way to view the unique items bought in the `Item` column?
df_data['Item'].unique()
Out[11]:
array(['Bread', 'Scandinavian', 'Hot chocolate', 'Jam', 'Cookies', 'Muffin', 'Coffee', 'Pastry', 'Medialuna', 'Tea', 'Tartine', 'Basket', 'Mineral water', 'Farm House', 'Fudge', 'Juice', "Ella's Kitchen Pouches", 'Victorian Sponge', 'Frittata', 'Hearty & Seasonal', 'Soup', 'Pick and Mix Bowls', 'Smoothies', 'Cake', 'Mighty Protein', 'Chicken sand', 'Coke', 'My-5 Fruit Shoot', 'Focaccia', 'Sandwich', 'Alfajores', 'Eggs', 'Brownie', 'Dulce de Leche', 'Honey', 'The BART', 'Granola', 'Fairy Doors', 'Empanadas', 'Keeping It Local', 'Art Tray', 'Bowl Nic Pitt', 'Bread Pudding', 'Adjustment', 'Truffles', 'Chimichurri Oil', 'Bacon', 'Spread', 'Kids biscuit', 'Siblings', 'Caramel bites', 'Jammie Dodgers', 'Tiffin', 'Olum & polenta', 'Polenta', 'The Nomad', 'Hack the stack', 'Bakewell', 'Lemon and coconut', 'Toast', 'Scone', 'Crepes', 'Vegan mincepie', 'Bare Popcorn', 'Muesli', 'Crisps', 'Pintxos', 'Gingerbread syrup', 'Panatone', 'Brioche and salami', 'Afternoon with the baker', 'Salad', 'Chicken Stew', 'Spanish Brunch', 'Raspberry shortbread sandwich', 'Extra Salami or Feta', 'Duck egg', 'Baguette', "Valentine's card", 'Tshirt', 'Vegan Feast', 'Postcard', 'Nomad bag', 'Chocolates', 'Coffee granules ', 'Drinking chocolate spoons ', 'Christmas common', 'Argentina Night', 'Half slice Monster ', 'Gift voucher', 'Cherry me Dried fruit', 'Mortimer', 'Raw bars', 'Tacos/Fajita'], dtype=object)
In [12]:
df_data.Item.unique()
Out[12]:
array(['Bread', 'Scandinavian', 'Hot chocolate', 'Jam', 'Cookies', 'Muffin', 'Coffee', 'Pastry', 'Medialuna', 'Tea', 'Tartine', 'Basket', 'Mineral water', 'Farm House', 'Fudge', 'Juice', "Ella's Kitchen Pouches", 'Victorian Sponge', 'Frittata', 'Hearty & Seasonal', 'Soup', 'Pick and Mix Bowls', 'Smoothies', 'Cake', 'Mighty Protein', 'Chicken sand', 'Coke', 'My-5 Fruit Shoot', 'Focaccia', 'Sandwich', 'Alfajores', 'Eggs', 'Brownie', 'Dulce de Leche', 'Honey', 'The BART', 'Granola', 'Fairy Doors', 'Empanadas', 'Keeping It Local', 'Art Tray', 'Bowl Nic Pitt', 'Bread Pudding', 'Adjustment', 'Truffles', 'Chimichurri Oil', 'Bacon', 'Spread', 'Kids biscuit', 'Siblings', 'Caramel bites', 'Jammie Dodgers', 'Tiffin', 'Olum & polenta', 'Polenta', 'The Nomad', 'Hack the stack', 'Bakewell', 'Lemon and coconut', 'Toast', 'Scone', 'Crepes', 'Vegan mincepie', 'Bare Popcorn', 'Muesli', 'Crisps', 'Pintxos', 'Gingerbread syrup', 'Panatone', 'Brioche and salami', 'Afternoon with the baker', 'Salad', 'Chicken Stew', 'Spanish Brunch', 'Raspberry shortbread sandwich', 'Extra Salami or Feta', 'Duck egg', 'Baguette', "Valentine's card", 'Tshirt', 'Vegan Feast', 'Postcard', 'Nomad bag', 'Chocolates', 'Coffee granules ', 'Drinking chocolate spoons ', 'Christmas common', 'Argentina Night', 'Half slice Monster ', 'Gift voucher', 'Cherry me Dried fruit', 'Mortimer', 'Raw bars', 'Tacos/Fajita'], dtype=object)
In [13]:
pd.unique(df_data['Item'])
Out[13]:
array(['Bread', 'Scandinavian', 'Hot chocolate', 'Jam', 'Cookies', 'Muffin', 'Coffee', 'Pastry', 'Medialuna', 'Tea', 'Tartine', 'Basket', 'Mineral water', 'Farm House', 'Fudge', 'Juice', "Ella's Kitchen Pouches", 'Victorian Sponge', 'Frittata', 'Hearty & Seasonal', 'Soup', 'Pick and Mix Bowls', 'Smoothies', 'Cake', 'Mighty Protein', 'Chicken sand', 'Coke', 'My-5 Fruit Shoot', 'Focaccia', 'Sandwich', 'Alfajores', 'Eggs', 'Brownie', 'Dulce de Leche', 'Honey', 'The BART', 'Granola', 'Fairy Doors', 'Empanadas', 'Keeping It Local', 'Art Tray', 'Bowl Nic Pitt', 'Bread Pudding', 'Adjustment', 'Truffles', 'Chimichurri Oil', 'Bacon', 'Spread', 'Kids biscuit', 'Siblings', 'Caramel bites', 'Jammie Dodgers', 'Tiffin', 'Olum & polenta', 'Polenta', 'The Nomad', 'Hack the stack', 'Bakewell', 'Lemon and coconut', 'Toast', 'Scone', 'Crepes', 'Vegan mincepie', 'Bare Popcorn', 'Muesli', 'Crisps', 'Pintxos', 'Gingerbread syrup', 'Panatone', 'Brioche and salami', 'Afternoon with the baker', 'Salad', 'Chicken Stew', 'Spanish Brunch', 'Raspberry shortbread sandwich', 'Extra Salami or Feta', 'Duck egg', 'Baguette', "Valentine's card", 'Tshirt', 'Vegan Feast', 'Postcard', 'Nomad bag', 'Chocolates', 'Coffee granules ', 'Drinking chocolate spoons ', 'Christmas common', 'Argentina Night', 'Half slice Monster ', 'Gift voucher', 'Cherry me Dried fruit', 'Mortimer', 'Raw bars', 'Tacos/Fajita'], dtype=object)
In [ ]: