- 作业一:
- Step 1.加载数据(datasets/users.csv)
- Step 2. 以occupation分组,求每一种职业所有用户的平均年龄
- Step 3. 求每一种职业男性的占比,作为新的一列(male_pct)添加到数据集中,并按照从低到高的顺序排列
- Step 4. 获取每一种职业对应的最大和最小的用户年龄
- Step 1. 导入数据并赋值给变量 chipo
- Step 2. 计算出有多商品大于10美元(去除列数据中特殊字符)
- Step 3. 每个项目的价格是多少?[指定列去重,筛选,排序]
- Step 4 根据商品的价格对数据进行排序
- Step 5.在所有商品订单中 最贵商品的数量(quantity)是多少?
- Step 6. 商品订购单中,商品 Veggie Salad Bowl 的订单数目?
- Step 7. 在所有订单中,购买商品Canned Soda数量大于1的订单数有几条?
数据集下载页面:javascript:void(0)
作业一:
Step 1.加载数据(datasets/users.csv)
| user_id | age | gender | occupation | zip_code |
0 | 1 | 24 | M | technician | 85711 |
1 | 2 | 53 | F | other | 94043 |
2 | 3 | 23 | M | writer | 32067 |
3 | 4 | 24 | M | technician | 43537 |
4 | 5 | 33 | F | other | 15213 |
5 | 6 | 42 | M | executive | 98101 |
6 | 7 | 57 | M | administrator | 91344 |
7 | 8 | 36 | M | administrator | 05201 |
… | … | … | … | … | … |
939 | 940 | 32 | M | administrator | 02215 |
940 | 941 | 20 | M | student | 97229 |
941 | 942 | 48 | F | librarian | 78209 |
942 | 943 | 22 | M | student | 77841 |
943 rows × 5 columns
Step 2. 以occupation分组,求每一种职业所有用户的平均年龄
Step 3. 求每一种职业男性的占比,作为新的一列(male_pct)添加到数据集中,并按照从低到高的顺序排列
Step 4. 获取每一种职业对应的最大和最小的用户年龄
作业二:(数据过滤与排序)
Step 1. 导入数据并赋值给变量 chipo
| order_id | quantity | item_name | choice_description | item_price |
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 |
5 | 3 | 1 | Chicken Bowl | [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou… | $10.98 |
6 | 3 | 1 | Side of Chips | NaN | $1.69 |
7 | 4 | 1 | Steak Burrito | [Tomatillo Red Chili Salsa, [Fajita Vegetables… | $11.75 |
8 | 4 | 1 | Steak Soft Tacos | [Tomatillo Green Chili Salsa, [Pinto Beans, Ch… | $9.25 |
9 | 5 | 1 | Steak Burrito | [Fresh Tomato Salsa, [Rice, Black Beans, Pinto… | $9.25 |
10 | 5 | 1 | Chips and Guacamole | NaN | $4.45 |
11 | 6 | 1 | Chicken Crispy Tacos | [Roasted Chili Corn Salsa, [Fajita Vegetables,… | $8.75 |
12 | 6 | 1 | Chicken Soft Tacos | [Roasted Chili Corn Salsa, [Rice, Black Beans,… | $8.75 |
13 | 7 | 1 | Chicken Bowl | [Fresh Tomato Salsa, [Fajita Vegetables, Rice,… | $11.25 |
14 | 7 | 1 | Chips and Guacamole | NaN | $4.45 |
15 | 8 | 1 | Chips and Tomatillo-Green Chili Salsa | NaN | $2.39 |
16 | 8 | 1 | Chicken Burrito | [Tomatillo-Green Chili Salsa (Medium), [Pinto … | $8.49 |
17 | 9 | 1 | Chicken Burrito | [Fresh Tomato Salsa (Mild), [Black Beans, Rice… | $8.49 |
18 | 9 | 2 | Canned Soda | [Sprite] | $2.18 |
19 | 10 | 1 | Chicken Bowl | [Tomatillo Red Chili Salsa, [Fajita Vegetables… | $8.75 |
… | … | … | … | … | … |
4617 | 1833 | 1 | Steak Burrito | [Fresh Tomato Salsa, [Rice, Black Beans, Sour … | $11.75 |
4618 | 1833 | 1 | Steak Burrito | [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese… | $11.75 |
4619 | 1834 | 1 | Chicken Salad Bowl | [Fresh Tomato Salsa, [Fajita Vegetables, Pinto… | $11.25 |
4620 | 1834 | 1 | Chicken Salad Bowl | [Fresh Tomato Salsa, [Fajita Vegetables, Lettu… | $8.75 |
4621 | 1834 | 1 | Chicken Salad Bowl | [Fresh Tomato Salsa, [Fajita Vegetables, Pinto… | $8.75 |
Step 2. 计算出有多商品大于10美元(去除列数据中特殊字符)
Step 3. 每个项目的价格是多少?[指定列去重,筛选,排序]
输出一个只包含[ item_name ]和 [item_price]两列的dataframe
| item_name | item_price |
606 | Steak Salad Bowl | 11.89 |
1229 | Barbacoa Salad Bowl | 11.89 |
1132 | Carnitas Salad Bowl | 11.89 |
7 | Steak Burrito | 11.75 |
168 | Barbacoa Crispy Tacos | 11.75 |
39 | Barbacoa Bowl | 11.75 |
… | … | … |
0 | Chips and Fresh Tomato Salsa | 2.39 |
40 | Chips | 2.15 |
6 | Side of Chips | 1.69 |
263 | Canned Soft Drink | 1.25 |
28 | Canned Soda | 1.09 |
34 | Bottled Water | 1.09 |
Step 4 根据商品的价格对数据进行排序
Step 5.在所有商品订单中 最贵商品的数量(quantity)是多少?
| order_id | quantity | item_name | choice_description | item_price |
3598 | 1443 | 15 | Chips and Fresh Tomato Salsa | NaN | 44.25 |
Step 6. 商品订购单中,商品 Veggie Salad Bowl 的订单数目?
Step 7. 在所有订单中,购买商品Canned Soda数量大于1的订单数有几条?