【问题标题】:format python list stored in bucket storage to read it with Bigquery格式化存储在存储桶中的 python 列表以使用 Bigquery 读取它
【发布时间】:2021-11-11 00:45:40
【问题描述】:

我有一个简单的项目列表:

['item1', 'item2', 'item3', etc...]

它们可能属于一个更大的对象,称为产品。

我发现以下格式有效,但项目嵌套在一行下。

{'product': ['item1', 'item2', 'item3']}

如何将我的列表转换为 bigquery 中每行一个项目,其中有一列名为 product

我正在 python 中的云函数中运行我的代码。

【问题讨论】:

    标签: python json google-bigquery google-cloud-storage


    【解决方案1】:

    如果您希望 BigQuery 中每行有一个项目:

    [{'product': 'item1'}, {'product': 'item2'}, {'product': 'item3'}]
    

    在 Python 中将您的项目列表转换为产品列表:

    items = ['item1', 'item2', 'item3']
    products = []
    for item in items:
        product = {'product': item}
        products.append(product)
    

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多