Python Pandas - 排序问题KeyError:

时间:2017-02-28 03:06:57

标签: python pandas

我正在尝试对熊猫数据框进行排序,但我得到的是KeyError。我希望能够根据已建立的conn而不是对象名称进行排序。

这是我的代码:

import pandas as pd
j = '''
{
    "VSER-HTTP-80": {
        "established conn": "1",
        "external ip": "10.54.110.89",
        "external port": 80,
        "members": [
            {
                "current status": "UP",
                "name": "SER-APNTPS01",
                "server ip": "10.50.30.29",
                "service group name": "SVC-GRP-HTTP-80",
                "service name": null,
                "service port": 80,
                "service type": "HTTP"
            }
        ]
    },
    "VSER-SSL-443": {
        "established conn": "22",
        "external ip": "204.154.110.89",
        "external port": 443,
        "members": [
            {
                "current status": "UP",
                "name": "SER-APNTPS01",
                "server ip": "10.30.30.29",
                "service group name": "SVC-GRP-HTTP-80",
                "service name": null,
                "service port": 80,
                "service type": "HTTP"
            }
        ]
    }
}
'''

df = pd.read_json(j)
df.sort(['established conn'])

这是我的索引:

df.index
Index([u'established conn', u'external ip', u'external port', u'members'], dtype='object')

这是我的错误:

  File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)
KeyError: 'established conn'

0 个答案:

没有答案