【问题标题】:How do I export a dataframe to a BigQuery table from Cloud Datalab?如何将数据框从 Cloud Datalab 导出到 BigQuery 表?
【发布时间】:2015-12-17 13:37:42
【问题描述】:

我在 Google Cloud Datalab 工作,我想将 Pandas 数据框导出为新的 BigQuery 表。我正在尝试遵循 Cloud Datalab 附带的在线帮助笔记本,但我可以看到没有导出到 BigQuery 的示例,仅导出到 Google Cloud Storage。

无论如何,我可以弄清楚如何使用正确的架构在 BigQuery 中创建表,但我不知道如何将实际数据放入表中!

这是我现在得到的:

dataset = bq.DataSet('calculations')
dataset.create(friendly_name='blah', 
               description='blah blah')
print 'Dataset exists', dataset.exists()

# Create the schema for the table we're about to create.
schema = bq.Schema.from_dataframe(measures[0]['data'])
print schema
print len(measures[0]['data'])

# Create a table for our results.
temptable = bq.Table('calculations.test').create(schema=schema, 
                                                 overwrite=True)

# How to export the actual data to the table?

所以这个输出:

True
[{'type': 'STRING', 'name': u'id'}, {'type': 'STRING', 'name': ...
8173

显示我的数据框有 8173 行。

如果我转到 BigQuery,我会看到该表已使用正确的架构创建,但其中没有数据。

我如何实际导出那里的数据?

如果不可能,那么我可以改为导出到 Cloud Storage,尽管我已经尝试过并且遇到了同样的问题。我更愿意导出到 BigQuery。

【问题讨论】:

    标签: python google-bigquery google-cloud-datalab


    【解决方案1】:

    您需要致电:

    temptable.insert_data(df)
    

    df 是你的 Pandas 数据框。

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 2021-06-07
      • 2017-11-13
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      相关资源
      最近更新 更多