Python 从 jupyter 服务器下载数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41627247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:20:13  来源:igfitidea点击:

Download data from a jupyter server

pythondownloadipythonjupyter-notebookjupyter

提问by Anh V? Nguy?n

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

我通过连接到服务器来使用 ipython notebook 我不知道如何以编程方式将事物(数据框、.csv 文件等)下载到我的本地计算机。因为我不能像 C://user// 那样具体声明路径......它将被下载到他们的机器而不是我的机器

回答by Sagar Dhungel

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.

文件 zipname.tar.gz 将保存在与您的笔记本相同的文件夹中。

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

此外,如果文件太大,请在同一个 notebook 块中执行以下操作

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

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

或者你可以使用这个扩展https://github.com/data-8/nbzip

回答by abutaleb haidary

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.

如果您使用的是 Jupyter Notebook,则可以转到 Notebook 左上角的“文件”选项卡,然后单击“打开”。它向您显示当前目录的内容。您可以选择不同格式(CSV、文本等)的数据文件,然后将其下载到本地计算机中。

Open tab in Jupyter notebook

在 Jupyter 笔记本中打开选项卡

enter image description here

在此处输入图片说明

Download your desired file

下载你想要的文件

enter image description here

在此处输入图片说明

回答by Tanguy

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.

解决方案是打开文件(无法正确读取,因为它是二进制文件),然后从笔记本的记事本中下载。

回答by Paul Rougieux

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:

根据另一个答案,以下函数会将 Pandas 数据框导出到 csv 文件,并且会为您提供一个链接以在浏览器中下载 csv 文件:

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 the above function and the code below in a jupyter notebook cell :

要获取 csv 文件的链接,请在 jupyter notebook 单元格中输入上述函数和以下代码:

csv_download_link(df, 'df.csv')

By default the argument delete_prompt=Truemakes 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.

默认情况下,该参数delete_prompt=True确保一旦您下载了 csv 文件,它就会被删除,因此该文件不会污染您自然存档笔记本的 git 存储库。