【问题标题】:Pandas read_gbq() does not load columns containing dotsPandas read_gbq() 不加载包含点的列
【发布时间】:2021-03-12 09:50:40
【问题描述】:

我正在使用 read_gbq() 使用以下代码将 Big Query 表加载到 Jupyter 笔记本中:

# Define SQL query
sql = """
    SELECT *
    FROM `xxx.xxx.xxx`
    WHERE timestamp > TIMESTAMP('2021-03-11 00:00:00') AND timestamp < TIMESTAMP('2021-03-12 00:00:00')
    ORDER BY timestamp 
"""
# Run a Standard SQL query using the environment's default project
df = pd.read_gbq(sql, dialect='standard')

该表被存储到 df 但名称中包含一个点的列,例如labels.type 不会被加载(它们只是丢失了,不会引发错误)。
当我在 BigQuery 本身中执行相同的查询时,我会在预览窗口中看到正确的表(即 labels.type 没有丢失)。

这可能是什么原因?

【问题讨论】:

    标签: python pandas google-bigquery jupyter-notebook


    【解决方案1】:

    它不起作用,因为labels.type 是一个嵌套对象/表。奇怪的是,它在 Big Query 预览中显示为扁平化。但是,在运行 SELECT `labels.type` ... 时,它在 Big Query 中也不起作用。

    为了解决这个问题,我选择了label 并使用pd.json_normalize() 在我的 Jupyter Notebook 中将其展平。

    【讨论】:

      猜你喜欢
      • 2015-08-25
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2018-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多