【问题标题】:Load nested data from firestore to pandas将嵌套数据从 firestore 加载到 pandas
【发布时间】:2021-05-18 06:58:37
【问题描述】:

您好,我想在 pandas 中使用我的 firestore 数据库中的嵌套数据。

我可以像这样加载未嵌套的条目

db = firestore.client() 
pushes = db.collection('pushes').get()  
pushes_dict = list(map(lambda x: x.to_dict(), pushes))
dfPushes = pd.DataFrame(pushes_dict)

它完美地展示了第一层的一切。

但是有 dfPushes['entities'] 在列的每个单元格中都有这样的数据

[{'e': 'breaking news'}, {'e': 'cdc'}]

我现在想提取这些数据并为数组中找到的每个实体创建一个新行。 excel中的一种转置。该行应填充实体json数组行中的其他相应数据。

【问题讨论】:

    标签: python json pandas google-cloud-firestore


    【解决方案1】:

    试试这个,它会将您的 e 扩展到新列

    pd.json_normalize(df, record_path=['entities'],  \
                      meta=['<parent field1>','<parent field2>', 'so on'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2019-07-17
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      相关资源
      最近更新 更多