# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.1 64-bit
#     name: python3
# ---

# # Ex1 - Filtering and Sorting Data

# This time we are going to pull data directly from the internet.
# Special thanks to: https://github.com/justmarkham for sharing the dataset and materials.
#
# ### Step 1. Import the necessary libraries

import pandas as pd

# ### Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv). 

url =  'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'

# ### Step 3. Assign it to a variable called chipo.

chipo = pd.read_csv(url, sep='\t')

# ### Step 4. How many products cost more than $10.00?

chipo['price_float'] = pd.to_numeric(chipo.item_price.str.slice(1))


chipo.head
(chipo['price_float'] > 10).sum()

chipo['price_per_item'] = chipo.price_float / chipo.quantity

product_prices = chipo.groupby('item_name').agg({'price_per_item':'max'})

(product_prices.price_per_item > 10).sum()

# ### Step 5. What is the price of each item? 
# ###### print a data frame with only two columns item_name and item_price

product_prices



chipo[chipo.item_name == 'Chicken Bowl']

# ### Step 6. Sort by the name of the item



product_prices.sort_index()

# ### Step 7. What was the quantity of the most expensive item ordered?

chipo.price_float.idxmax()

chipo.loc[3598, :]





# ### Step 8. How many times was a Veggie Salad Bowl ordered?

chipo[chipo.item_name == 'Veggie Salad Bowl'].quantity.sum()

# ### Step 9. How many times did someone order more than one Canned Soda?

(chipo[chipo.item_name == 'Canned Soda'].quantity > 1).sum()

StarcoderdataJupyterScriptsDedupFiltered