PythonPandas不认识/t delimi

2024-05-15 23:18:06 发布

您现在位置:Python中文网/ 问答频道 /正文

做这个练习是为了学习熊猫。我认为根据错误提供的数据库有问题。你知道吗

想法?你知道吗

代码:

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_id\tquantity\titem_name\tchoice_description\titem_price
0    1\t1\tChips and Fresh Tomato Salsa\tNULL\t$2.39           
1                    1\t1\tIzze\t[Clementine]\t$3.39           
2             1\t1\tNantucket Nectar\t[Apple]\t$3.39           
3  1\t1\tChips and Tomatillo-Green Chili Salsa\tN...           
4  2\t2\tChicken Bowl\t[Tomatillo-Red Chili Salsa...           
5  3\t1\tChicken Bowl\t[Fresh Tomato Salsa (Mild)...           
6                   3\t1\tSide of Chips\tNULL\t$1.69           
7  4\t1\tSteak Burrito\t[Tomatillo Red Chili Sals...           
8  4\t1\tSteak Soft Tacos\t[Tomatillo Green Chili...           
9  5\t1\tSteak Burrito\t[Fresh Tomato Salsa, [Ric... 

Tags: andimporturlasenginepdt1fresh
1条回答
网友
1楼 · 发布于 2024-05-15 23:18:06

使用\t作为分隔符by tab

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   

相关问题 更多 >