2.3 Data Processing Cases in Python

Key Points

  • Review of the previous assignment
  • Demonstration of data processing

Pre-Class Preparation

None

Course Content

Review of the Previous Assignment

(Demonstration)

Demonstration of Data Processing

a = {
    "data": [
        {
            "creator": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "Martin",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "Martin",
                "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": "Martin",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "Martin",
                "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": "Martin",
                "username": "cxt7777"
            },
            "updater": {
                "_id": "5cecd40dd23e194ab0867aab",
                "name": "Martin",
                "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 structure parsing

  • Assign the data to the variable "data_iphone"

Variable name

data_iphone

Data type

Dictionary

Key data type

String

key

‘data’

Access value by key

data_iphone[‘data’]

Value data type

List

value

[{‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘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’: ‘Martin’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘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’: ‘Martin’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘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’}]

  • Parsing of data_iphone value

Variable name

data_iphone[‘data’]

Data type

List

Get the first data in the list

data_iphone[‘data’][0]

Value of the first data in the list

{‘creator’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘username’: ‘cxt7777’}, ‘updater’: {‘_id’: ‘5cecd40dd23e194ab0867aab’, ‘name’: ‘Martin’, ‘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’}

Data type of the first data in the list

Dictionary

Value of the key '_widget_1557886562320' in the first data in the list

data_iphone['data'][0]['_widget_1557886562320']

Was this information helpful?
Yes
NoNo
Need more help? Contact support