Python for Data Analysis_2nd_Task 5 之 Pandas 进阶
十道经典练习,使用Pandas,一起玩转数据分析
- 开始了解你的数据:探索 Chipotle 快餐数据
- 数据过滤与排序:探索 2012 欧洲杯数据
- 数据分组:探索酒类消费数据
- Apply 函数:探索 1960-2014 美国犯罪数据
- 合并:探索虚拟姓名数据
- 统计:探索风速数据
- 可视化:探索泰坦尼克灾难数据
- 创建数据框:探索 Pokemon 数据
- 时间序列:探索 Apple 公司股价数据
- 删除数据:探索 Iris 纸鸢花数据
开始了解你的数据:探索 Chipotle 快餐数据
探索 Chipotle 快餐数据
查看对应的数据集文件路径
ls ../input/pandas_exercise/exercise_data/
Apple_stock.csv drinks.csv second_cars_info.csv wechart.csv
cars.csv Euro2012_stats.csv train.csv wind.data
chipotle.tsv iris.csv US_Crime_Rates_1960_2014.csv
Step 1 导入必要的库
import pandas as np
Step 2 导入数据集
path1 = "../input/pandas_exercise/exercise_data/chipotle.tsv"
Step 3 将数据集存入 chipo 的 DataFrame 类型
chipo = pd.read_csv(path1, sep = '\t')
Step 4 查看前 10 行内容
chipo.head(10)
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
Step 5 产看数据集中的列数
# columns
chipo.shape[1]
5
# rows
chipo.shape[0]
4622
Step 6 打印全部列名
chipo.columns
Index(['order_id', 'quantity', 'item_name', 'choice_description',
'item_price'],
dtype='object')
chipo.info # [4622 rows x 5 columns]
<bound method DataFrame.info of order_id quantity item_name \
0 1 1 Chips and Fresh Tomato Salsa
1 1 1 Izze
2 1 1 Nantucket Nectar
3 1 1 Chips and Tomatillo-Green Chili Salsa
4 2<