Exporting Data from google colab to local machine

丶灬走出姿态 提交于 2019-12-04 09:20:41

问题


How to export data frames which are created in google colab to your local machine?

I have cleaned a data set on google colab. Now I want to export the data frame to my local machine. df.to_csv is saving file to the virtual machine and not my local machine.


回答1:


Try this

from google.colab import files
files.download("data.csv")

Update(Sep 2018): now it's even easier

  • open the left pane
  • select 'Files' tab
  • click 'Refresh'
  • right click the file, then download



回答2:


Try this:

First you can save the file using pandas to_csv functionality later on you can download that file using google colab files functionality.

from google.colab import files
df.to_csv('filename.csv') 
files.download('filename.csv')



回答3:


You can download the csv to your associated google drive. First you must install PyDrive.

!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from google.colab import files
from oauth2client.client import GoogleCredentials

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

This will generate a token in a browser for you to then paste into an input box that will be shown in your notebook.

Save your pandas data frame df.to_csv('mydataframe.csv', sep='\t')

To keep things neat you can create a new folder in your drive and then use the following:

file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() for file1 in file_list: print('title: %s, id: %s' % (file1['title'], file1['id']))

which will list the files and folders in your google drive and their id that you will need for the following step.

file = drive.CreateFile({'parents':[{u'id': 'id of folder you want to save in'}]}) file.SetContentFile("mydataframe.csv") file.Upload()

It will now be in your google drive in the given folder.



来源:https://stackoverflow.com/questions/49394737/exporting-data-from-google-colab-to-local-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!