做这个练习来学习熊猫。我认为根据错误提供的数据库有问题。
想法?
代码:
import numpy as np
import scipy as sp
import pandas as pd
import matplotlib as mpl
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
chipo = pd.read_csv(url, delimiter='/t')
print(chipo.head(10))
输出:
ex22_chipotle.py:7: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from 's+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
chipo = pd.read_csv(url, delimiter='/t')
order_idtquantitytitem_nametchoice_descriptiontitem_price
0 1t1tChips and Fresh Tomato SalsatNULLt$2.39
1 1t1tIzzet[Clementine]t$3.39
2 1t1tNantucket Nectart[Apple]t$3.39
3 1t1tChips and Tomatillo-Green Chili SalsatN...
4 2t2tChicken Bowlt[Tomatillo-Red Chili Salsa...
5 3t1tChicken Bowlt[Fresh Tomato Salsa (Mild)...
6 3t1tSide of ChipstNULLt$1.69
7 4t1tSteak Burritot[Tomatillo Red Chili Sals...
8 4t1tSteak Soft Tacost[Tomatillo Green Chili...
9 5t1tSteak Burritot[Fresh Tomato Salsa, [Ric...
通过tab
:使用t
作为分隔符
chipo = pd.read_csv(url, delimiter='t')
print(chipo.head(10))
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 2 Chicken Bowl
5 3 1 Chicken Bowl
6 3 1 Side of Chips
7 4 1 Steak Burrito
8 4 1 Steak Soft Tacos
9 5 1 Steak Burrito
choice_description item_price
0 NaN $2.39
1 [Clementine] $3.39
2 [Apple] $3.39
3 NaN $2.39
4 [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98
5 [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou... $10.98
6 NaN $1.69
7 [Tomatillo Red Chili Salsa, [Fajita Vegetables... $11.75
8 [Tomatillo Green Chili Salsa, [Pinto Beans, Ch... $9.25
9 [Fresh Tomato Salsa, [Rice, Black Beans, Pinto... $9.25