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
import pandas as pd
import numpy as np
Step 2. Import the dataset from this address .
Step 3. Assign it to a variable called chipo.
chipo = pd.read_csv('https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv' ,sep= ' \t ' )
chipo.head()
0
1
1
Chips and Fresh Tomato Salsa
NaN
$2.39
1
1
1
Izze
[Clementine]
$3.39
2
1
1
Nantucket Nectar
[Apple]
$3.39
3
1
1
Chips and Tomatillo-Green Chili Salsa
NaN
$2.39
4
2
2
Chicken Bowl
[Tomatillo-Red Chili Salsa (Hot), [Black Beans...
$16.98
Step 4. How many products cost more than $10.00?
chipo['item_price' ] = chipo['item_price' ].apply (lambda x:float (x[1 :]))
chipo_4 = chipo.drop_duplicates(['item_name' ,'quantity' ])
chipo_4 = chipo_4[chipo_4.quantity == 1 ]
chipo_4[chipo_4.item_price > 10 ].item_name.nunique()
Step 5. What is the price of each item?
print a data frame with only two columns item_name and item_price
chipo_5 = chipo.drop_duplicates(['item_name' ])
chipo_5 = chipo_5[chipo_5.quantity == 1 ]
chipo_5[['item_name' ,'item_price' ]]
0
Chips and Fresh Tomato Salsa
2.39
1
Izze
3.39
2
Nantucket Nectar
3.39
3
Chips and Tomatillo-Green Chili Salsa
2.39
6
Side of Chips
1.69
7
Steak Burrito
11.75
8
Steak Soft Tacos
9.25
10
Chips and Guacamole
4.45
11
Chicken Crispy Tacos
8.75
12
Chicken Soft Tacos
8.75
16
Chicken Burrito
8.49
21
Barbacoa Burrito
8.99
27
Carnitas Burrito
8.99
33
Carnitas Bowl
8.99
34
Bottled Water
1.09
38
Chips and Tomatillo Green Chili Salsa
2.95
39
Barbacoa Bowl
11.75
40
Chips
2.15
44
Chicken Salad Bowl
8.75
54
Steak Bowl
8.99
56
Barbacoa Soft Tacos
9.25
57
Veggie Burrito
11.25
62
Veggie Bowl
11.25
92
Steak Crispy Tacos
9.25
111
Chips and Tomatillo Red Chili Salsa
2.95
168
Barbacoa Crispy Tacos
11.75
186
Veggie Salad Bowl
11.25
191
Chips and Roasted Chili-Corn Salsa
2.39
233
Chips and Roasted Chili Corn Salsa
2.95
237
Carnitas Soft Tacos
9.25
250
Chicken Salad
10.98
263
Canned Soft Drink
1.25
298
6 Pack Soft Drink
6.49
300
Chips and Tomatillo-Red Chili Salsa
2.39
510
Burrito
7.40
520
Crispy Tacos
7.40
554
Carnitas Crispy Tacos
9.25
664
Steak Salad
8.99
674
Chips and Mild Fresh Tomato Salsa
3.00
738
Veggie Soft Tacos
11.25
1132
Carnitas Salad Bowl
11.89
1229
Barbacoa Salad Bowl
11.89
1414
Salad
7.40
1653
Veggie Crispy Tacos
8.49
1694
Veggie Salad
8.49
3750
Carnitas Salad
8.99
Step 6. Sort by the name of the item
chipo_5[['item_name' ,'item_price' ]].sort_values(by= 'item_name' )
298
6 Pack Soft Drink
6.49
39
Barbacoa Bowl
11.75
21
Barbacoa Burrito
8.99
168
Barbacoa Crispy Tacos
11.75
1229
Barbacoa Salad Bowl
11.89
56
Barbacoa Soft Tacos
9.25
34
Bottled Water
1.09
510
Burrito
7.40
263
Canned Soft Drink
1.25
33
Carnitas Bowl
8.99
27
Carnitas Burrito
8.99
554
Carnitas Crispy Tacos
9.25
3750
Carnitas Salad
8.99
1132
Carnitas Salad Bowl
11.89
237
Carnitas Soft Tacos
9.25
16
Chicken Burrito
8.49
11
Chicken Crispy Tacos
8.75
250
Chicken Salad
10.98
44
Chicken Salad Bowl
8.75
12
Chicken Soft Tacos
8.75
40
Chips
2.15
0
Chips and Fresh Tomato Salsa
2.39
10
Chips and Guacamole
4.45
674
Chips and Mild Fresh Tomato Salsa
3.00
233
Chips and Roasted Chili Corn Salsa
2.95
191
Chips and Roasted Chili-Corn Salsa
2.39
38
Chips and Tomatillo Green Chili Salsa
2.95
111
Chips and Tomatillo Red Chili Salsa
2.95
3
Chips and Tomatillo-Green Chili Salsa
2.39
300
Chips and Tomatillo-Red Chili Salsa
2.39
520
Crispy Tacos
7.40
1
Izze
3.39
2
Nantucket Nectar
3.39
1414
Salad
7.40
6
Side of Chips
1.69
54
Steak Bowl
8.99
7
Steak Burrito
11.75
92
Steak Crispy Tacos
9.25
664
Steak Salad
8.99
8
Steak Soft Tacos
9.25
62
Veggie Bowl
11.25
57
Veggie Burrito
11.25
1653
Veggie Crispy Tacos
8.49
1694
Veggie Salad
8.49
186
Veggie Salad Bowl
11.25
738
Veggie Soft Tacos
11.25
Step 7. What was the quantity of the most expensive item ordered?
chipo_5.sort_values(by= 'item_name' ).tail(1 )
738
304
1
Veggie Soft Tacos
[Tomatillo Red Chili Salsa, [Fajita Vegetables...
11.25
Step 8. How many times was a Veggie Salad Bowl ordered?
len (chipo[chipo.item_name == 'Veggie Salad Bowl' ])
Step 9. How many times did someone order more than one Canned Soda?
len (chipo[(chipo.item_name == 'Canned Soda' ) & (chipo.quantity > 1 )])