<jupyter_start><jupyter_text>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<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv).   Step 3. Assign it to a variable called chipo.<jupyter_code>chipo = pd.read_csv("https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv", delimiter="\t")<jupyter_output><empty_output><jupyter_text>Step 4. How many products cost more than $10.00? Tips: Which is a faster way to convert item prices from str to float?<jupyter_code>%timeit chipo["item_price"].str.replace("$", "").astype("float")
%timeit chipo["item_price"].apply(lambda s: float(s.replace("$", "")))
%timeit [float(s[1:-1]) for s in chipo["item_price"]]
chipo["item_price"] = chipo["item_price"].str.replace("$", "").astype("float")
chipo[chipo["item_price"] > 10]["item_name"].nunique()
# or should I filter to rows of quantity = 1 as the solution shows?
# What does "product" mean here? is that not an item? or a combination of an item and a choice?<jupyter_output><empty_output><jupyter_text>Step 5. What is the price of each item?  print a data frame with only two columns item_name and item_price<jupyter_code># OK, Let's omit rows whose quantity is more than 1
# and drop duplicates to see the prices of all the combinations of items and choices available in the data
chipo_items = chipo[chipo['quantity'] == 1][["item_name", "choice_description", "item_price"]].drop_duplicates(["item_name", "choice_description", "item_price"])
chipo_items<jupyter_output><empty_output><jupyter_text>Step 6. Sort by the name of the item<jupyter_code>chipo_items.sort_values(by="item_name")<jupyter_output><empty_output><jupyter_text>Step 7. What was the quantity of the most expensive item ordered?<jupyter_code>chipo.sort_values(by="item_price", ascending=False).head(1)<jupyter_output><empty_output><jupyter_text>Step 8. How many times was a Veggie Salad Bowl ordered?<jupyter_code>chipo[chipo["item_name"] == "Veggie Salad Bowl"]["order_id"].nunique()<jupyter_output><empty_output><jupyter_text>Step 9. How many times did someone order more than one Canned Soda?<jupyter_code>chipo[(chipo["item_name"] == "Canned Soda") & (chipo["quantity"] > 1)]
# The solution answers as 20 (number of rows of this table), but the actual number of orders is 18 because there are 2 orders having more than 1 canned soda order.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12299065420560748, 'fraction_numerical': 0.011588785046728972, 'mean_word_length': 6.964285714285714, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '457025', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 903, 'n_tokens_neox': 865, 'n_words': 260, 'path': '02_Filtering_&_Sorting/Chipotle/Exercises.ipynb', 'repo_name': 'chopstickexe/pandas_exercises', 'size': '2675'}