2016-09-24 1 views
-1

ich entlang den Beispielen von Python für Datenanalyse folgende bin und die ersten Beispiele zeigt:Python für Datenanalyse Fehler: Wert: Zeile 1, Spalte 1 (char 0)

In [15]: path = 'ch02/usagov_bitly_data2012-03-16-1331923249.txt' 
In [16]: open(path).readline() 
Out[16]: '{ "a": "Mozilla\\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\\/535.11 
(KHTML, like Gecko) Chrome\\/17.0.963.78 Safari\\/535.11", "c": "US", "nk": 1, 
"tz": "America\\/New_York", "gr": "MA", "g": "A6qOVH", "h": "wfLQtf", "l": 
"orofrog", "al": "en-US,en;q=0.8", "hh": "1.usa.gov", "r": 
"http:\\/\\/www.facebook.com\\/l\\/7AQEFzjSi\\/1.usa.gov\\/wfLQtf", "u": 
"http:\\/\\/www.ncbi.nlm.nih.gov\\/pubmed\\/22415991", "t": 1331923247, "hc": 
1331822918, "cy": "Danvers", "ll": [ 42.576698, -70.954903 ] }\n' 

Nachdem Sie diese Anweisungen befolgen ich :

In [21]: open(path).readline() 
Out[21]: '{ "a": "Mozilla\\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\\/535.11 
(KHTML, like Gecko) Chrome\\/17.0.963.78 Safari\\/535.11", "c": "US", "nk": 1, " 
tz": "America\\/New_York", "gr": "MA", "g": "A6qOVH", "h": "wfLQtf", "l": "orofr 
og", "al": "en-US,en;q=0.8", "hh": "1.usa.gov", "r": "http:\\/\\/www.facebook.co 
m\\/l\\/7AQEFzjSi\\/1.usa.gov\\/wfLQtf", "u": "http:\\/\\/www.ncbi.nlm.nih.gov\\ 
/pubmed\\/22415991", "t": 1331923247, "hc": 1331822918, "cy": "Danvers", "ll": [ 
42.576698, -70.954903 ] }\n' 

Der einzige Unterschied zu dem Buch ist der "ï» ¿"Teil.

Später, als ich versuche:

import json 
path = 'ch02/usagov_bitly_data2012-03-16-1331923249.txt' 
records = [json.loads(line) for line in open(path)] 

... was ich bekommen ist:

`In [22]: import json 

In [23]: path = 'usagov_bitly_data2012-03-16-1331923249.txt' 

In [24]: records = [json.loads(line) for line in open(path)] 
--------------------------------------------------------------------------- 
JSONDecodeError       Traceback (most recent call last) 
<ipython-input-24-b1e0b494454a> in <module>() 
----> 1 records = [json.loads(line) for line in open(path)] 

<ipython-input-24-b1e0b494454a> in <listcomp>(.0) 
----> 1 records = [json.loads(line) for line in open(path)] 

C:\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_ 
float, parse_int, parse_constant, object_pairs_hook, **kw) 
    317    parse_int is None and parse_float is None and 
    318    parse_constant is None and object_pairs_hook is None and not 
kw): 
--> 319   return _default_decoder.decode(s) 
    320  if cls is None: 
    321   cls = JSONDecoder 

C:\Anaconda3\lib\json\decoder.py in decode(self, s, _w) 
    337 
    338   """ 
--> 339   obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
    340   end = _w(s, end).end() 
    341   if end != len(s): 

C:\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx) 
    355    obj, end = self.scan_once(s, idx) 
    356   except StopIteration as err: 
--> 357    raise JSONDecodeError("Expecting value", s, err.value) from 
None 
    358   return obj, end 


JSONDecodeError: Expecting value: line 1 column 1 (char 0)` 

Hat jemand wissen, warum ich diesen JSONDecodeError Fehler bekommen?

Antwort

0

Sir, ï »¿, Es ist nicht JSON-Format, ich denke, dass Sie Anomalie Text 'ï» ¿' entfernen oder versuchen sollten, einige Online-Format JSON, um klarer zu sein.

+0

Vielen Dank für Ihre Antwort. Wenn ich die Datei als txt-Format öffne, wird diese Anomalie nicht angezeigt, daher kann ich sie nicht entfernen. –

Verwandte Themen