Write a Pandas DataFrame to Google Cloud Storage or BigQuery

前端 未结 8 1225
予麋鹿
予麋鹿 2020-12-02 13:16

Hello and thanks for your time and consideration. I am developing a Jupyter Notebook in the Google Cloud Platform / Datalab. I have created a Pandas DataFrame and would like

8条回答
  •  广开言路
    2020-12-02 13:52

    Uploading to Google Cloud Storage without writing a temporary file and only using the standard GCS module

    from google.cloud import storage
    import os
    import pandas as pd
    
    # Only need this if you're running this code locally.
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'/your_GCP_creds/credentials.json'
    
    df = pd.DataFrame(data=[{1,2,3},{4,5,6}],columns=['a','b','c'])
    
    client = storage.Client()
    bucket = client.get_bucket('my-bucket-name')
        
    bucket.blob('upload_test/test.csv').upload_from_string(df.to_csv(), 'text/csv')
    

提交回复
热议问题