python提取json数据索引必须是整数_关于json:收到“ValueError:如果使用所有标量值,则必须在Python中传递索引”...

郑燕七
2023-12-01

I now get the following error:

--------------------------------------------------------------------------- ValueError Traceback (most recent call

last) in ()

1 for ticker in tickers:

----> 2 CryptoDataCSV(ticker, 86400)

in CryptoDataCSV(symbol, frequency)

7 url ='https://poloniex.com/public?command=returnChartData&currencyPair='+symbol+'&end=9999999999&period='+str(frequency)+'&start=0'

8

----> 9 df = pd.read_json(url)

10

11 df.set_index('date',inplace=True)

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in

read_json(path_or_buf, orient, typ, dtype, convert_axes,

convert_dates, keep_default_dates, numpy, precise_float, date_unit,

encoding, lines)

352 obj = FrameParser(json, orient, dtype, convert_axes, convert_dates,

353 keep_default_dates, numpy, precise_float,

--> 354 date_unit).parse()

355

356 if typ == 'series' or obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in parse(self)

420

421 else:

--> 422 self._parse_no_numpy()

423

424 if self.obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in

_parse_no_numpy(self)

637 if orient =="columns":

638 self.obj = DataFrame(

--> 639 loads(json, precise_float=self.precise_float), dtype=None)

640 elif orient =="split":

641 decoded = dict((str(k), v)

~\Anaconda3\lib\site-packages\pandas\core\frame.py in init(self,

data, index, columns, dtype, copy)

273 dtype=dtype, copy=copy)

274 elif isinstance(data, dict):

--> 275 mgr = self._init_dict(data, index, columns, dtype=dtype)

276 elif isinstance(data, ma.MaskedArray):

277 import numpy.ma.mrecords as mrecords

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_dict(self,

data, index, columns, dtype)

409 arrays = [data[k] for k in keys]

410

--> 411 return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)

412

413 def _init_ndarray(self, values, index, columns, dtype=None, copy=False):

~\Anaconda3\lib\site-packages\pandas\core\frame.py in

_arrays_to_mgr(arrays, arr_names, index, columns, dtype) 5494 # figure out the index, if necessary 5495 if index is None:

-> 5496 index = extract_index(arrays) 5497 else: 5498 index = _ensure_index(index)

~\Anaconda3\lib\site-packages\pandas\core\frame.py in

extract_index(data) 5533 5534 if not indexes and not

raw_lengths:

-> 5535 raise ValueError('If using all scalar values, you must pass' 5536 ' an index') 5537

ValueError: If using all scalar values, you must pass an index

 类似资料: