2.3 Python 資料處理案例講解

本節要點

  • Jodoo 資料處理演示

課前準備

課程內容

Jodoo 資料處理演示

a = {
    "data": [
        {
            "creator": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "deleter": null,
            "createTime": "2020-03-26T02:41:06.491Z",
            "updateTime": "2020-03-26T02:46:27.825Z",
            "deleteTime": null,
            "_widget_1557886562320": "iPhone 11",
            "_widget_1557886562335": "5998",
            "_widget_1557886562350": "17",
            "_id": "5e7c164229e01a00063be284",
            "appId": "5e798363b587cc0006b40445",
            "entryId": "5cdb765b5a6ae613aeed0f84"
        },
        {
            "creator": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "deleter": null,
            "createTime": "2020-03-26T02:47:02.037Z",
            "updateTime": "2020-03-26T02:47:02.037Z",
            "deleteTime": null,
            "_widget_1557886562320": "iPhone X",
            "_widget_1557886562335": "4998",
            "_widget_1557886562350": "5",
            "_id": "5e7c17a650bccb0006441778",
            "appId": "5e798363b587cc0006b40445",
            "entryId": "5cdb765b5a6ae613aeed0f84"
        },
        {
            "creator": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "查理",
                "username": "cxt7777"
            },
            "deleter": null,
            "createTime": "2020-03-26T02:47:43.059Z",
            "updateTime": "2020-03-26T02:47:43.059Z",
            "deleteTime": null,
            "_widget_1557886562320": "iPhone 8",
            "_widget_1557886562335": "3998",
            "_widget_1557886562350": "32",
            "_id": "5e7c17cfcd87510006cf8189",
            "appId": "5e798363b587cc0006b40445",
            "entryId": "5cdb765b5a6ae613aeed0f84"
        }
    ]
}

資料結構解析

  • 將資料賦值給變數data_iphone後

變數名

data_iphone

資料類型

字典

key資料類型

字串

key

‘data’

透過key取得value

data_iphone[‘data’]

value資料類型

列表

value

[{‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘deleter’: None, ‘createTime’: ‘2020-03-26T02:41:06.491Z’, ‘updateTime’: ‘2020-03-26T02:46:27.825Z’, ‘deleteTime’: None, ‘_widget_1557886562320’: ‘iPhone 11’, ‘_widget_1557886562335’: ‘5998’, ‘_widget_1557886562350’: ‘17’, ‘_id’: ‘5e7c164229e01a00063be284’, ‘appId’: ‘5e798363b587cc0006b40445’, ‘entryId’: ‘5cdb765b5a6ae613aeed0f84’}, {‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘deleter’: None, ‘createTime’: ‘2020-03-26T02:47:02.037Z’, ‘updateTime’: ‘2020-03-26T02:47:02.037Z’, ‘deleteTime’: None, ‘_widget_1557886562320’: ‘iPhone X’, ‘_widget_1557886562335’: ‘4998’, ‘_widget_1557886562350’: ‘5’, ‘_id’: ‘5e7c17a650bccb0006441778’, ‘appId’: ‘5e798363b587cc0006b40445’, ‘entryId’: ‘5cdb765b5a6ae613aeed0f84’}, {‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘deleter’: None, ‘createTime’: ‘2020-03-26T02:47:43.059Z’, ‘updateTime’: ‘2020-03-26T02:47:43.059Z’, ‘deleteTime’: None, ‘_widget_1557886562320’: ‘iPhone 8’, ‘_widget_1557886562335’: ‘3998’, ‘_widget_1557886562350’: ‘32’, ‘_id’: ‘5e7c17cfcd87510006cf8189’, ‘appId’: ‘5e798363b587cc0006b40445’, ‘entryId’: ‘5cdb765b5a6ae613aeed0f84’}]

  • data_iphone的value解析

變數名

data_iphone[‘data’]

資料類型

列表

取得列表中第一個資料

data_iphone[‘data’][0]

列表中第一個資料的值

{‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘查理’, ‘username’: ‘cxt7777’}, ‘deleter’: None, ‘createTime’: ‘2020-03-26T02:41:06.491Z’, ‘updateTime’: ‘2020-03-26T02:46:27.825Z’, ‘deleteTime’: None, ‘_widget_1557886562320’: ‘iPhone 11’, ‘_widget_1557886562335’: ‘5998’, ‘_widget_1557886562350’: ‘17’, ‘_id’: ‘5e7c164229e01a00063be284’, ‘appId’: ‘5e798363b587cc0006b40445’, ‘entryId’: ‘5cdb765b5a6ae613aeed0f84’}

列表中第一個資料的資料類型

字典

列表中第一個資料中的key為’_widget_1557886562320’的value

data_iphone[‘data’][0][‘_widget_1557886562320’]

這項資訊有幫助嗎?
需要更多協助嗎?聯繋技術支援。