简体   繁体   English

如何从Cloud Datalab将数据框导出到BigQuery表?

[英]How do I export a dataframe to a BigQuery table from Cloud Datalab?

I'm working in Google Cloud Datalab and I want to export a Pandas dataframe as a new BigQuery table. 我正在Google Cloud Datalab中工作,我想将Pandas数据框导出为新的BigQuery表。 I'm trying to follow the online help notebooks that come with Cloud Datalab, though I can see are no examples of exporting to BigQuery, only to Google Cloud Storage. 我正在尝试遵循Cloud Datalab随附的在线帮助笔记本,尽管我看不到仅导出到Google Cloud Storage的示例,也没有导出到BigQuery的示例。

Anyway, I can work out how to create the table in BigQuery with the correct schema, but I can't work out how to get the actual data into the table! 无论如何,我可以解决如何使用正确的架构在BigQuery中创建表,但是无法解决如何将实际数据放入表中!

This is what I've got now: 这就是我现在得到的:

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?

So this outputs: 所以这输出:

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

showing that my dataframe has 8173 rows. 显示我的数据框有8173行。

If I go to BigQuery, I see that the table has been created with the correct schema, but it has no data in it. 如果我转到BigQuery,则会看到该表是使用正确的架构创建的,但是其中没有数据。

How do I actually export the data there? 我实际上如何在那里导出数据?

If it's impossible then I could export to Cloud Storage instead, though I've tried that and am having the same problem. 如果不可能,那么我可以导出到Cloud Storage,尽管我已经尝试过并且遇到了同样的问题。 I would prefer to export to BigQuery. 我希望导出到BigQuery。

You need to call: 您需要致电:

temptable.insert_data(df)

where df is your Pandas dataframe. df是您的Pandas数据框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在datalab中将数据从pandas dataframe批量上传到bigquery表中 - How can i bulk upload data into bigquery table from pandas dataframe in datalab 我不能在datalab中查询bigquery表吗? - I can not consult bigquery table in datalab? 从Google Cloud Datalab向BigQuery插入数据时,如何调试解析错误? - How to debug parse error when inserting data to BigQuery from Google Cloud Datalab? 使用Cloud Datalab中的Pandas(来自bigquery)跟踪错误删除重复项 - Remove duplicates with Pandas in Cloud Datalab (from bigquery) traceback error 使用Google Cloud Datalab时如何将.gz文件加载到BigQuery? - How to load .gz files to BigQuery when using Google Cloud Datalab? Google Cloud DataLab + BigQuery:如何设定地区/区域/位置 - Google Cloud DataLab + BigQuery: how to set region/zone/location 如何将一个巨大的表作为一个文件从 BigQuery 导出到 Google 云存储桶中 - How to export a huge table from BigQuery into a Google cloud bucket as one file Datalab:如何将Big Query标准SQL查询导出到数据框? - Datalab: How to export Big Query standard SQL query to dataframe? Google Cloud BigQuery load_table_from_dataframe()实木复合地板AttributeError - Google Cloud BigQuery load_table_from_dataframe() Parquet AttributeError 如何将数据从Google存储云读取到Google云数据板 - How to read data from Google storage cloud to Google cloud datalab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM