[Python] Export dataframe as csv file from google colab to google drive

Discussão em 'Python' iniciado por Stack, Maio 6, 2025.

  1. Stack

    Stack Membro Participativo

    I want to upload a dataframe as csv from colab to google drive.I tried a lot but no luck. I can upload a simple text file but failed to upload a csv.

    I tried the following code:

    import pandas as pd
    df=pd.DataFrame({1:[1,2,3]})
    df.to_csv('abc',sep='\t')
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    uploaded = drive.CreateFile({'title': 'sample.csv', 'mimeType':'csv'})
    uploaded.SetContentFile('abc')
    uploaded.Upload()

    Continue reading...

Compartilhe esta Página