27

I'm using ipython notebook by connecting to a server I don't know how to download a thing (data frame, .csv file,... for example) programatically to my local computer. Because I can't specific declare the path like C://user//... It will be downloaded to their machine not mine

Anh Vũ Nguyễn
  • 593
  • 2
  • 6
  • 11

5 Answers5

24

Run this in separate cell in one of the notebooks:

!tar cvfz zipname.tar.gz *

To cover more folders up the tree, write ../ before the * for every step up the directory.

tar cvfz zipname.tar.gz ../../*

The file zipname.tar.gz will be saved in the same folder as your notebook.

Also if files size is too large execute the following in same notebook block

!split -b 200m allfiles.tar.gz allfiles.tar.gz.part

Alternatively you can use this extension https://github.com/data-8/nbzip

Sagar Dhungel
  • 391
  • 2
  • 6
16

If you are using Jupyter notebook, you can go to the "File" tab on the top left part of the notebook and click "Open". It shows you the content of the current directory. You can select your data file with different format (CSV, text, etc) and then you can download it in your local computer.

Open tab in Jupyter notebook

enter image description here

Download your desired file

enter image description here

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
14

Based on another answer, the following function will export a pandas data frame to a csv file and it will provide you with a link to download the csv file in your browser:

def csv_download_link(df, csv_file_name, delete_prompt=True):
    """Display a download link to load a data frame as csv from within a Jupyter notebook"""
    df.to_csv(csv_file_name, index=False)
    from IPython.display import FileLink
    display(FileLink(csv_file_name))
    if delete_prompt:
        a = input('Press enter to delete the file after you have downloaded it.')
        import os
        os.remove(csv_file_name)

To get a link to a csv file, enter or import the above function and use the code below in a jupyter notebook cell :

csv_download_link(df, 'df.csv')

By default the argument delete_prompt=True makes sure that once you have downloaded the csv file, it gets deleted so the file doesn't pollute the git repository where you naturally archive your notebooks (converted in markdown format with jupytext for meaningful diffs).

Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110
7

The download option did not appear for me.

The solution was to open the file (which could not be correctly read as it was a binary file), and to download it from the notebook's notepad.

Tanguy
  • 3,124
  • 4
  • 21
  • 29
1

You can also download the files directly from the Jupyter dashboard. To open it, either click on the Jupyter icon in the top left corner, or alternatively select Open... from the File menu:

Open Jupyter dashboard

After the dashboard has opened, select the file you want to download by checking the check box to the left of it. A Download button will appear in the actions bar above:

Select and download file

buddemat
  • 4,552
  • 14
  • 29
  • 49