<jupyter_start><jupyter_text>Visualizing Chipotle's 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 collections
import matplotlib.pyplot as plt 

# set this so the graphs open internally
%matplotlib inline<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># import os
# os.environ['http_proxy']='http://dev-proxy.oa.com:8080'
# os.environ['https_proxy']='http://dev-proxy.oa.com:8080'
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
chipo = pd.read_csv(url, header = 0, 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. Create a histogram of the top 5 items bought<jupyter_code>top5 = chipo['item_name'].value_counts()[0:5].to_frame().reset_index()
top5.columns = ['item_name', 'cnt']
top5.plot(kind = 'bar', x = 'item_name', y = 'cnt')<jupyter_output><empty_output><jupyter_text>Step 6. Create a scatterplot with the number of items orderered per order price Hint: Price should be in the X-axis and Items ordered in the Y-axis<jupyter_code># 不理解业务 不追求做法的准确性 重点在于语法、用法的掌握
price_numorder = chipo.groupby(['item_price']).agg('sum')['quantity'].reset_index()
price_numorder.columns = ['item_price', 'numorder']
price_numorder['item_price'] = price_numorder['item_price'].apply(lambda x: float(x.strip('$')))
# 与 plt.scatter 语法一致
price_numorder.plot(kind = 'scatter', x = 'item_price', y = 'numorder')
plt.xlabel('Order Price')
plt.ylabel('Items ordered')
plt.title('Number of items ordered per order price')
plt.ylim(0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1358087487283825, 'fraction_numerical': 0.014242115971515769, 'mean_word_length': 6.774703557312253, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '175687', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 726, 'n_tokens_neox': 703, 'n_words': 161, 'path': '07_Visualization/Chipotle/Exercises.ipynb', 'repo_name': 'moqiguzhu/pandas_exercises', 'size': '1966'}