How can I download a pandas Dataframe in Google Colab?

For google colab, i recommend use Pydrive. Your answer can be found in here How to download file created in Colaboratory workspace?

edit: just change filename.csv to filename.zip or filename.blabla in lines

uploaded = drive.CreateFile({'title': 'filename.csv'})
uploaded.SetContentFile('filename.csv')

why? because this line

uploaded.SetContentFile('filename.csv')

auto set format for you content file, so you don't need to converter it to String or Byte.


Maybe something like this.

from google.colab import files

df.to_csv('df.csv')
files.download('df.csv')