<jupyter_start><jupyter_text>Ex2 - Getting and Knowing your 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
import numpy as np<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>url = "https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv"
chipo = pd.read_csv(url,sep='\t')<jupyter_output><empty_output><jupyter_text>Step 4. See the first 10 entries<jupyter_code>chipo.head(10)<jupyter_output><empty_output><jupyter_text>Step 5. What is the number of observations in the dataset?<jupyter_code># Solution 1
chipo.info()
# Solution 2
len(chipo)<jupyter_output><empty_output><jupyter_text>Step 6. What is the number of columns in the dataset?<jupyter_code>len(chipo.columns)<jupyter_output><empty_output><jupyter_text>Step 7. Print the name of all the columns.<jupyter_code>print(chipo.columns)<jupyter_output>Index(['order_id', 'quantity', 'item_name', 'choice_description',
       'item_price'],
      dtype='object')<jupyter_text>Step 8. How is the dataset indexed?<jupyter_code>print(chipo.index)<jupyter_output>RangeIndex(start=0, stop=4622, step=1)<jupyter_text>Step 9. Which was the most-ordered item?<jupyter_code>qty_sorted_orders = chipo.groupby("item_name").sum()
qty_sorted_orders = qty_sorted_orders.sort_values(["quantity"], ascending = False)
qty_sorted_orders.iloc[0].name<jupyter_output><empty_output><jupyter_text>Step 10. For the most-ordered item, how many items were ordered?<jupyter_code>qty_sorted_orders["quantity"][0]<jupyter_output><empty_output><jupyter_text>Step 11. What was the most ordered item in the choice_description column?<jupyter_code>most_ordered_by_desc = chipo.groupby("choice_description").sum().sort_values(["quantity"], ascending = False)
print(most_ordered_by_desc.iloc[0].name)<jupyter_output>[Diet Coke]<jupyter_text>Step 12. How many items were orderd in total?<jupyter_code>print(most_ordered_by_desc.iloc[0].quantity)<jupyter_output>159<jupyter_text>Step 13. Turn the item price into a float  Step 13.a. Check the item price type<jupyter_code>chipo.item_price.dtype<jupyter_output><empty_output><jupyter_text>Step 13.b. Create a lambda function and change the type of item price<jupyter_code>dollarizer = lambda x: float(x[1:-1])
chipo.item_price = chipo.item_price.apply(dollarizer)<jupyter_output><empty_output><jupyter_text>Step 13.c. Check the item price type<jupyter_code>chipo.item_price.dtype<jupyter_output><empty_output><jupyter_text>Step 14. How much was the revenue for the period in the dataset?<jupyter_code>revenue = np.sum(chipo.item_price * chipo.quantity)
print(revenue)<jupyter_output>39237.02<jupyter_text>Step 15. How many orders were made in the period?<jupyter_code>num_of_orders = len(chipo["order_id"].unique())
#num_of_orders = chipo.order_id.value_counts().count()
print(num_of_orders)<jupyter_output>1834<jupyter_text>Step 16. What is the average revenue amount per order?<jupyter_code># Solution 1
chipo["revenue"] = chipo["item_price"] * chipo["quantity"]
avg_rev = chipo.groupby("order_id").sum().revenue.mean()
print("the average revenue is: " + str(avg_rev))
# Solution 2
chipo.groupby('order_id').sum().mean()['revenue']<jupyter_output><empty_output><jupyter_text>Step 17. How many different items are sold?<jupyter_code>len(chipo["item_name"].unique())
chipo["item_name"].value_counts().count()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12208355941399891, 'fraction_numerical': 0.018448182311448725, 'mean_word_length': 8.381679389312977, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, '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': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '202638', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1308, 'n_words': 256, 'path': '01_Getting_&_Knowing_Your_Data/Chipotle/Exercises.ipynb', 'repo_name': 'YairAmar/pandas_tutorial', 'size': '3686'}