最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to improve performance when processing large datasets with loops in Python? - Stack Overflow

programmeradmin4浏览0评论

I’m working with a large dataset that I fetch using this code:

    response = await client.get(tenant_url, headers=headers, params=params)
    response.raise_for_status()
    data = response.json()
    numpy_2d_arrays = np.array([[device["id"]["id"], device["name"]] for device in data["data"]])

To improve performance, I’m considering converting the data to a Polar DataFrame before extracting the id and name. Will this help improve performance, or is there a better way to handle large datasets in loops?

I’d appreciate any suggestions or performance tips!

data is

{
  "data": [
    {
      "id": {
        "entityType": "DEVICE",
        "id": "7c4145c0-e533-11ef-9681-df1aaf416822"
      },
      "name": "C4DEE264E540-002"
    },
    {
      "id": {
        "entityType": "DEVICE",
        "id": "be7b4b90-b36a-11ed-9188-71dcc7f44f0f"
      },
      "name": "C4DEE264E540"
    },
    {
      "id": {
        "entityType": "DEVICE",
        "id": "fbcded60-de0e-11ef-9681-df1aaf416822"
      },
      "name": "C4DEE264E540-001"
    }
  ],
  "totalPages": 1,
  "totalElements": 3,
  "hasNext": false
}
发布评论

评论列表(0)

  1. 暂无评论