Splitting json data in python -


i'm trying manipulate list of items in python im getting error "attributeerror: 'list' object has no attribute 'split'" understand list not understand .split don't know else do. below copy paste of relevant part of code.

tourl = 'http://data.bitcoinity.org/chart_data' tovalues = {'timespan':'24h','resolution':'hour','currency':'usd','exchange':'all','mining_pool':'all','compare':'no','data_type':'price_volume','chart_type':'line_bar','smoothing':'linear','chart_types':'ccacdfcdaa'} todata = urllib.urlencode(tovalues) toreq = urllib2.request(tourl, todata) tores = urllib2.urlopen(toreq) tores2 = tores.read() tos = json.loads(tores2) tola = tos["data"] item in tola:     ting = item.get("values")     ting.split(',')[2]       <-----error     print(ting) 

to understand i'm trying need see json data. ting outputs this:

[   [1379955600000l, 123.107310846774], [1379959200000l, 124.092526428571],   [1379962800000l, 125.539504822835], [1379966400000l, 126.27024617931],   [1379970000000l, 126.723474983766], [1379973600000l, 126.242406356837],   [1379977200000l, 124.788410570987], [1379980800000l, 126.810084904632],   [1379984400000l, 128.270580796748], [1379988000000l, 127.892411269036],   [1379991600000l, 126.140579640523], [1379995200000l, 126.513705084746],   [1379998800000l, 128.695124951923], [1380002400000l, 128.709738051044],   [1380006000000l, 125.987767097378], [1380009600000l, 124.323433535528],   [1380013200000l, 123.359378559603], [1380016800000l, 125.963250678733],   [1380020400000l, 125.074618194444], [1380024000000l, 124.656345088853],   [1380027600000l, 122.411303435449], [1380031200000l, 124.145747100372],   [1380034800000l, 124.359452274881], [1380038400000l, 122.815357211394],   [1380042000000l, 123.057706915888] ]  [   [1379955600000l, 536.4739135], [1379959200000l, 1235.42506637],   [1379962800000l, 763.16329656], [1379966400000l, 804.04579319],   [1379970000000l, 634.84689741], [1379973600000l, 753.52716718],    [1379977200000l, 506.90632968], [1379980800000l, 494.473732950001],   [1379984400000l, 437.02095093], [1379988000000l, 176.25405034],   [1379991600000l, 319.80432715], [1379995200000l, 206.87212398],   [1379998800000l, 638.47226435], [1380002400000l, 438.18036666],   [1380006000000l, 512.68490443], [1380009600000l, 904.603705539997],   [1380013200000l, 491.408088450001], [1380016800000l, 670.275397960001],   [1380020400000l, 767.166941339999], [1380024000000l, 899.976089609997],    [1380027600000l, 1243.64963909], [1380031200000l, 1508.82429811],   [1380034800000l, 1190.18854705], [1380038400000l, 546.504592349999],    [1380042000000l, 206.84883264] ] 

and ting[0] outputs this:

[1379955600000l, 123.187067936508] [1379955600000l, 536.794013499999] 

what i'm trying add values ting[0-24] comes after second comma. made me try split not work

help appreciated!

you have list; commas put there python delimit values when printing list.

just access element 2 directly:

print ting[2] 

this prints:

[1379962800000, 125.539504822835] 

each of entries in item['values'] (so ting) list of 2 float values, can address each of index 0 , 1:

>>> print ting[2][0] 1379962800000 >>> print ting[2][1] 125.539504822835 

to list of second values, use list comprehension:

second_vals = [t[1] t in ting] 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -