Python pandas json 2D array -


relatively new pandas, have json , python files:

{"dataset":{     "id": 123,     "data": [["2015-10-16",1,2,3,4,5,6],              ["2015-10-15",7,8,9,10,11,12],              ["2015-10-14",13,14,15,16,17]] }} 

&

import pandas x = pandas.read_json('sample.json') y = x.dataset.data print x.dataset 

printing x.dataset , y works fine, when go access sub-element y, returns 'buffer' type. what's going on? how can access data inside array? attempting y[0][1] returns out of bounds error, , iterating through returns strange series of 'nul' characters , yet, appears able return first portion of data after printing x.dataset...

the data attribute of pandas series points memory buffer of data contained in series:

>>> df = pandas.read_json('sample.json') >>> type(df.dataset) pandas.core.series.series >>> type(df.dataset.data) memoryview 

if have column/row named "data", have access it's string name, e.g.:

>>> type(df.dataset['data']) list 

because of surprises this, it's considered best practice access columns through indexing rather through attribute access. if this, desired result:

>>> df['dataset']['data'] [['2015-10-16', 1, 2, 3, 4, 5, 6],  ['2015-10-15', 7, 8, 9, 10, 11, 12],  ['2015-10-14', 13, 14, 15, 16, 17]]  >>> arr = df['dataset']['data'] >>> arr[0][0] '2015-10-16' 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -