-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpizza_practice_python.py
More file actions
45 lines (32 loc) · 941 Bytes
/
pizza_practice_python.py
File metadata and controls
45 lines (32 loc) · 941 Bytes
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
# imports Libraries
import pandas as pd
import matplotlib.pyplot as plt
# example data
data = {
'Pizza_Name': ['BBQ Chicken', 'Cheese', 'Truffle Special', 'Pepperoni'],
'Price': [12.50, 8.99, 25.00, 14.50]
}
# create dataframe
df = pd.DataFrame(data)
print(df)
# create function to check premium and buget pizzas
def lable_pizza(price):
if price > 15:
return "Premium"
else:
return "Budget"
# apply' command function ko har row pe chalata hai
df['Category'] = df['Price'].apply(lable_pizza)
print(df)
# create a group by category
revenue = df.groupby('Category')['Price'].sum()
print(revenue)
revenue_2 = df.groupby('Category')['Price'].count()
print(revenue_2)
# Graph using matplotlib
revenue.plot(kind='bar', color=['skyblue', 'orange'])
# Thoda sajate hain
plt.title("Budget vs Premium: Kaun Jeeta?")
plt.xlabel("Category")
plt.ylabel("Total Paisa ($)")
plt.show() # Show the Chart