-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoodWheel.py
104 lines (67 loc) · 2.24 KB
/
FoodWheel.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#------------1
import codecademylib
from matplotlib import pyplot as plt
import pandas as pd
restaurants = pd.read_csv('restaurants.csv')
print(restaurants.head())
cuisine_options_count = restaurants.cuisine.nunique()
cuisine_counts = restaurants.groupby('cuisine').name.count().reset_index()
print(cuisine_counts)
#-----------2
import codecademylib3
from matplotlib import pyplot as plt
import pandas as pd
restaurants = pd.read_csv('restaurants.csv')
cuisine_counts = restaurants.groupby('cuisine')\
.name.count()\
.reset_index()
counts=cuisine_counts.name.values
cuisines=restaurants.cuisine.unique()
print(cuisines)
print(counts)
plt.pie(counts,labels=cuisines,shadow=True,autopct='%d%%')
plt.axis('equal')
plt.show()
#-----------3
import codecademylib
from matplotlib import pyplot as plt
import pandas as pd
orders = pd.read_csv('orders.csv')
print orders.head()
orders['month'] = orders.date.apply(lambda x: x.split('-')[0])
print orders.head()
avg_order = orders.groupby('month').price.mean().reset_index()
std_order = orders.groupby('month').price.std().reset_index()
#---------4
import codecademylib
from matplotlib import pyplot as plt
import pandas as pd
orders = pd.read_csv('orders.csv')
orders['month'] = orders.date.apply(lambda x: x.split('-')[0])
avg_order = orders.groupby('month').price.mean().reset_index()
std_order = orders.groupby('month').price.std().reset_index()
ax = plt.subplot()
bar_heights = avg_order.price
bar_errors = std_order.price
plt.bar(range(len(bar_heights)),
bar_heights,
yerr=bar_errors,
capsize=5)
ax.set_xticks(range(len(bar_heights)))
ax.set_xticklabels(['April', 'May', 'June', 'July', 'August', 'September'])
plt.ylabel('Average Order Amount')
plt.title('Order Amount over Time')
plt.show()
#----------5
import codecademylib
from matplotlib import pyplot as plt
import pandas as pd
orders = pd.read_csv('orders.csv')
customer_amount = orders.groupby('customer_id').price.sum().reset_index()
print customer_amount.head()
plt.hist(customer_amount.price.values,
range=(0, 200), bins=40)
plt.xlabel('Total Spent')
plt.ylabel("Number of Customers")
plt.title('Customer Expenditure Over 6 Months')
plt.show()