forked from TheUpshot/chipotle
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pandas_chipotle.py
74 lines (41 loc) · 1.28 KB
/
pandas_chipotle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# coding: utf-8
# In[10]:
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import re
data = pd.read_csv('/Users/minnawin/PythonWorkInProgress/orders.tsv', sep="\t")
df = DataFrame(data)
print(df.head())
# In[8]:
items = df.item_name
print(items)
# In[11]:
print(df.item_price)
# In[28]:
most_ordered = df.item_name.value_counts()
print("Most ordered item: Number:\n")
print("=======================================================\n%s ")%(most_ordered)
# In[30]:
ten_most_ordered = df.item_name.value_counts()[:9]
print(most_ordered)
# In[33]:
df.item_name.value_counts()[:10].plot(kind='bar')
# In[34]:
#Convert the item_price into float, after you remove the '$'
df['item_price'] = df['item_price'].str.replace('$','')
df['item_price'] = df['item_price'].astype(float)
print(df['item_price'])
# In[35]:
orders = df.groupby('order_id').sum()
orders.head()
orders['item_price'].describe()
# In[42]:
#Average number of items per order
#First, get the total number of items per order id
total_num_items = df.groupby('order_id')['quantity'].sum()
#print(total_num_items)
#Then calculate the average/mean
avg_num_items_per_order = total_num_items.mean()
print("Average number of items per order: %.2f")%(avg_num_items_per_order)
# In[ ]: