【问题标题】:Read data stored in zip file in Google Cloud Storage from Notebook in Google Cloud Datalab从 Google Cloud Datalab 中的 Notebook 读取存储在 Google Cloud Storage 中的 zip 文件中的数据
【发布时间】:2016-06-03 09:13:34
【问题描述】:

我有一个 zip 文件,其中包含一个相对较大的数据集 (1Gb),存储在 Google Cloud Storage 实例中的一个 zip 文件中。

我需要使用托管在 Google Cloud Datalab 中的笔记本来访问该文件以及其中包含的数据。我该怎么办?

谢谢。

【问题讨论】:

    标签: google-cloud-storage google-cloud-datalab


    【解决方案1】:

    您可以尝试以下方法吗?

    import pandas as pd
    
    # Path to the object in Google Cloud Storage that you want to copy
    sample_gcs_object = 'gs://path-to-gcs/Hello.txt.zip'
    
    # Copy the file from Google Cloud Storage to Datalab
    !gsutil cp $sample_gcs_object 'Hello.txt.zip'
    
    # Unzip the file
    !unzip 'Hello.txt.zip' 
    
    # Read the file into a pandas DataFrame
    pandas_dataframe = pd.read_csv('Hello.txt')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2020-06-13
      相关资源
      最近更新 更多