美文网首页
jupyter notebook

jupyter notebook

作者: caokai001 | 来源:发表于2018-12-10 22:17 被阅读9次

    添加R kernel

    【原文】(https://blog.csdn.net/jacke121/article/details/75378645

    简单的方法:通过Anaconda安装R内核
    
    conda install -c r r-essentials
    # 稍微麻烦的方法:手动安装R内核
    如果你不是用Anaconda,过程会有点复杂,首先,你需要从CRAN安装R。 
    之后,启动R控制台,运行下面的语句:
    
    install.packages(c('repr', 'IRdisplay', 'crayon', 'pbdZMQ', 'devtools'))
    devtools::install_github('IRkernel/IRkernel')
    IRkernel::installspec()  # to register the kernel in the current R installation
    

    在同一个notebook里运行R和Python

    要这么做,最好的方法事安装rpy2(需要一个可以工作的R),用pip操作很简单:
    pip install rpy2
    然后,就可以同时使用两种语言了,甚至变量也可以在二者之间公用:

    In [1]: %load_ext rpy2.ipython
    In [2]: %R require(ggplot2)
    Out[2]: array([1], dtype=int32)
    In [3]: import pandas as pd
            df = pd.DataFrame({
                    'Letter': ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'],
                    'X': [4, 3, 5, 2, 1, 7, 7, 5, 9],
                    'Y': [0, 4, 3, 6, 7, 10, 11, 9, 13],
                    'Z': [1, 2, 3, 1, 2, 3, 1, 2, 3]
                })
    In [4]: %%R -i df
            ggplot(data = df) + geom_point(aes(x = X, y= Y, color = Letter, size = Z))
    

    tips: 安装jupyter notebook

    1.安装anaconda,并添加环境变量
    2.添加清华,中科大的镜像提高下载速度
    3.使用conda,pip 安装jupyter notebook
        pip install jupyter/conda install jupyter
    4.(当使用xshell登录服务器,需要在属性-->隧道中添加xmanager,实现UI界面)
    $ jupyter-notebook
    5.弹出火狐浏览器界面,就可以正常使用jupyter notebook
    

    相关文章

      网友评论

          本文标题:jupyter notebook

          本文链接:https://www.haomeiwen.com/subject/kvhjhqtx.html