简体   繁体   中英

Can someone help me to understand why my csv is being read as a html doctype?

I am attempting to read a csv file into Jupyter notebook using Panadas. When I read the file and index the columns, I get a message that reads

Index(['<'!DOCTYPE HTML>'], dtype='object')

I'm uncertain why my file is being read as an html doctype and I can't read any of the columns in it's current format. I also get errors when II convert the file to excel. Can anyone point me in the right direction as to what the issue might be? Thank you.

import numpy as np
import pandas as pd

inspection = pd.read_csv("http://localhost:8889/view/Desktop/python/Data/Inspections_MergedFile.csv", sep='\t')

inspection.columns

The csv data is taken from NYC's open data file on restaurant inspection: https://data.cityofnewyork.us/Health/DOHMH-New-York-City-Restaurant-Inspection-Results/xx67-kt59 which was joined with 311's data on food poisoning https://data.cityofnewyork.us/Social-Services/food-poisoning/gjkf-etq5 .

If you're trying to serve the file locally through some web api route then you'll have to provide more information about your app and what constructions you have laid out.

When I try the following off the link you provided and copying the link for their export options for the csv format I get the data downloaded (eventually after several minutes), albeit with a warning...

>>> df = pandas.read_csv( 'https://data.cityofnewyork.us/api/views/xx67-kt59/rows.csv' )
sys:1: DtypeWarning: Columns (6) have mixed types. Specify dtype option on import or set low_memory=False.
>>> df
           CAMIS                               DBA           BORO BUILDING  \
0       41471806                     THE HEN HOUSE       BROOKLYN     7302
1       50060020                  CURRY EXPRESS NY      MANHATTAN      130
2       50060627            RED HOUSE ASIAN FUSION         QUEENS    19203
3       50040866                        FUEL GRILL      MANHATTAN      112
4       41710571                     BLACKTHORN 51         QUEENS     8012
5       50015486                       THE IZAKAYA      MANHATTAN      326
6       50015250              PETITE BLUE DOG CAFE      MANHATTAN      119
7       40388091                            MASAWA      MANHATTAN     1239
8       41456998                     A.I.G.CHARTIS      MANHATTAN      175
9       50006741                        GRACE CAFE      MANHATTAN      572
10      41377069              CATALDO'S RESTAURANT       BROOKLYN      554
11      41145911                   WA LUNG KITCHEN      MANHATTAN      557
12      41547536               MINT'S THAI KITCHEN         QUEENS     7015
13      41066771                    DUNKIN' DONUTS       BROOKLYN     5702
14      40365472            SPAIN RESTAURANT & BAR      MANHATTAN      113
15      50072117                               NaN      MANHATTAN      307
16      50042671                      EDGAR'S CAFE      MANHATTAN      650
17      41490991                   LIPS RESTAURANT      MANHATTAN      227
18      41713624  BIENVENIDOS AL CALLAO RESTAURANT         QUEENS    11122
19      40923012                          DOMINO'S      MANHATTAN      200
20      41477406                  CIBAO RESTAURANT         QUEENS    10422
21      50013522             BREWKLYN GRIND COFFEE       BROOKLYN      557
22      41212364                         BECKETT'S      MANHATTAN       81
23      50066646                    TOKOYO EXPRESS         QUEENS     7057
24      41575815                   BLACKOUT LOUNGE         QUEENS    13316
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM