首页 > 解决方案 > 将数据集从 google cloud datalab 导出到 google colab

问题描述

我在我的 Google Cloud 数据实验室中创建了一个数据集,我想在 Google Colab 中继续处理它(使用 Python)。我不知道应该如何将我的数据集导出到 Google Colab(或 Jupyter)。你能帮我吗?

这是我在 Google Datalab 中的数据集:

%sql --module afewrecords
Select pickup_datetime, dropoff_datetime, pickup_longitude,
pickup_latitude, dropoff_longitude, dropoff_latitude, passenger_count,
trip_distance, tolls_amount, fare_amount, total_amount
 
From [nyc-tlc:yellow.trips] LIMIT 10

trips = bq.Query(afewrecords).to_dataframe()
trips

我想在 Google Colab 中旅行。

提前致谢。

标签: pythongoogle-cloud-platformjupyter-notebookgoogle-colaboratorydata-mining

解决方案


为了将您的 BigQuery 数据读入 Colab 实例中的 DataFrame,您需要:

  1. 如果您没有,请使用Cloud Resource Manager创建一个项目;
  2. 为项目启用计费
  3. 启用 BigQuery API,以便您可以与 BigQuery 进行交互;

完成这些步骤后,您可以使用文档中的此代码段。请注意,from google.colab import auth auth.authenticate_user()验证您访问 BigQuery 的请求。此外,您将使用pd.io.gbq.read_gbq()来编写查询。


推荐阅读