2016-03-28 16 views

回答

1

您不能直接将其转换为JSON。

替代方法如下:

fields = [] # Create an empty list to hold the field names 
for fieldName in data.fields: # Iterate the field names 
    fields.append(fieldName) # Add to the list 

result = []   
for row in data: # Iterate each row 
    currentRow = {} 
    count = 0 
    for value in row: 
     currentRow[fields[count]] = value # Add each value with corresponding key from fields 
     count = count + 1 
    result.append(currentRow) 
print(json.dumps(result)) 
0

因为它是一个大火数据对象。具有自己的函数和对象的对象,你不能完全编码为json。阅读:How to make a class JSON serializable


如果你只是想看看变量信息使用pprint功能。

0

如果您想要JSON文件的交互式视图,只需评估其名称即可。您将获得相应的print data.__repr__()

from blaze import Data 
from blaze.utils import example 

data = Data(example('accounts.json')) 
data 

# amount  name 
# 0  100 Alice 
# 1 -200  Bob 
# 2  300 Charlie 
# 3  400 Dennis 
# 4 -500 Edith