【发布时间】:2014-06-06 03:43:33
【问题描述】:
我有以下数据
{ "results": [
{
"company": "XYZ",
"createdAt": "2014-03-27T23:21:48.758Z",
"email": "abc@gmail.com",
"firstName": "abc",
"lastName": "xyz",
"linkedinAccount": "",
"location": "",
"profilePicture": {
"__type": "File",
"name": "ab0e-profilePicture",
"url": "url.url.com"
},
"registrationGate": "normal",
"telephone": "",
"title": "AA",
"updatedAt": "2014-03-27T23:24:20.220Z",
"username": "abc@gmail.com",
"zipcode": "00000"
}
]
}
我使用以下代码导入 json 数据
import json
import pandas as pd
from pandas import DataFrame
json_data = pd.read_json('data.json')
print json_data[:2]
这会打印出来
results
0 {u'linkedinAccount': u'', u'username': u'abc...
1 {u'linkedinAccount': u'zxcflcnv', u'username...
[2 rows x 1 columns]
当我尝试使用
打印列时print df['linkedinAccount']
我收到以下错误
KeyError: u'no item named linkedinAccount'
如何根据列名访问数据框中的数据?
【问题讨论】:
-
@U2EF1,它是相似的,但我认为如果你同意的话,这个解决方案对于这种情况不太理想。