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()
Loading a Dataset from the Google Drive to Google Colab Click the link given. Then you'll see the usual google account authentication steps and after two steps you'll see authentication keys for your google drive. Now add it in the early appeared shell and press enter. Now your google drive is mounted.
It may be easier to use mounting instead of pydrive.
from google.colab import drive drive.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
drive.mount('/drive')
df.to_csv('/drive/My Drive/folder_name/name_csv_file.csv')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With