Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I download a pandas Dataframe in Google Colab? [duplicate]

I have been stuck on how to download a pandas DataFrame into my local disk (or onto Google Drive) after creating it in Google Colab. I have tried converting it to bytes, a string (using pd.to_string), a dict (pd.to_dict), but nothing seems to work.

Additionally, I've looked at using the drive.CreateFile method as explained in the intro Colab Code and as specified here: How to download file created in Colaboratory workspace?, but I'm not sure how to apply this to pandas.

Any help is appreciated - thanks!

like image 594
Brian Li Avatar asked Feb 18 '18 18:02

Brian Li


People also ask

How do I duplicate a Pandas DataFrame?

To copy Pandas DataFrame, use the copy() method. The DataFrame. copy() method makes a copy of the provided object's indices and data. The copy() method accepts one parameter called deep, and it returns the Series or DataFrame that matches the caller.

How do I import pandas to Google Colab?

To start, log into your Google Account and go to Google Drive. Click on the New button on the left and select Colaboratory if it is installed (if not click on Connect more apps, search for Colaboratory and install it). From there, import Pandas as shown below (Colab has it installed already).


1 Answers

Maybe something like this.

from google.colab import files

df.to_csv('df.csv')
files.download('df.csv')
like image 157
korakot Avatar answered Sep 27 '22 20:09

korakot