将数据集从 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 中进行旅行。

提前致谢。

解决方法

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

  1. 使用 Cloud Resource Manager 创建一个项目(如果您没有);
  2. Enable billing 用于项目;
  3. 启用 BigQuery API,以便您可以与 BigQuery 交互;

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