Export dataframe as csv file from google colab to google drive
It may be easier to use mounting instead of pydrive.
from google.colab import drivedrive.mount('drive')
After authentication, you can copy your csv file.
df.to_csv('data.csv')!cp data.csv "drive/My Drive/"
Without using !cp command
from google.colab import drive
- Mounts the google drive to Colab Notebook
drive.mount('/drive')
- Make sure the folder Name is created in the google drive before uploading
df.to_csv('/drive/My Drive/folder_name/name_csv_file.csv')
# Import Drive API and authenticate.from google.colab import drive# Mount your Drive to the Colab VM.drive.mount('/gdrive')# Write the DataFrame to CSV file.with open('/gdrive/My Drive/foo.csv', 'w') as f: df.to_csv(f)