How to use R and Python in same notebook on Google Colab

Поділитися
Вставка
  • Опубліковано 7 лют 2025
  • In this video, I will show you how to use the magic command so that you can simultaneously use R and Python in the same notebook on Google Colab (also works locally in Jupyter notebook).
    🌟 Buy me a coffee: www.buymeacoff...
    ⭕ Code:
    ✅ github.com/dat...
    ⭕ Playlist:
    Check out our other videos in the following playlists.
    ✅ Data Science 101: bit.ly/datapro...
    ✅ Data Science UA-camr Podcast: bit.ly/datasci...
    ✅ Data Science Virtual Internship: bit.ly/datapro...
    ✅ Bioinformatics: bit.ly/dataprof...
    ✅ Data Science Toolbox: bit.ly/datapro...
    ✅ Streamlit (Web App in Python): bit.ly/datapro...
    ✅ Shiny (Web App in R): bit.ly/datapro...
    ✅ Google Colab Tips and Tricks: bit.ly/datapro...
    ✅ Pandas Tips and Tricks: bit.ly/datapro...
    ✅ Python Data Science Project: bit.ly/datapro...
    ✅ R Data Science Project: bit.ly/datapro...
    ⭕ Subscribe:
    If you're new here, it would mean the world to me if you would consider subscribing to this channel.
    ✅ Subscribe: www.youtube.co...
    ⭕ Recommended Tools:
    Kite is a FREE AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite and I love it!
    ✅ Check out Kite: www.kite.com/g...
    ⭕ Recommended Books:
    ✅ Hands-On Machine Learning with Scikit-Learn : amzn.to/3hTKuTt
    ✅ Data Science from Scratch : amzn.to/3fO0JiZ
    ✅ Python Data Science Handbook : amzn.to/37Tvf8n
    ✅ R for Data Science : amzn.to/2YCPcgW
    ✅ Artificial Intelligence: The Insights You Need from Harvard Business Review: amzn.to/33jTdcv
    ✅ AI Superpowers: China, Silicon Valley, and the New World Order: amzn.to/3nghGrd
    ⭕ Stock photos, graphics and videos used on this channel:
    ✅ 1.envato.marke...
    ⭕ Follow us:
    ✅ Medium: bit.ly/chanin-m...
    ✅ FaceBook: / dataprofessor
    ✅ Website: dataprofessor.org/ (Under construction)
    ✅ Twitter: / thedataprof
    ✅ Instagram: / data.professor
    ✅ LinkedIn: / chanin-nantasenamat
    ✅ GitHub 1: github.com/dat...
    ✅ GitHub 2: github.com/cha...
    ⭕ Disclaimer:
    Recommended books and tools are affiliate links that gives me a portion of sales at no cost to you, which will contribute to the improvement of this channel's contents.
    #dataprofessor #R #conda #anaconda #miniconda #jupyternotebook #jupyter #googlecolab #colaboratory #notebook #machinelearning #datascienceproject #randomforest #decisiontree #svm #neuralnet #neuralnetwork #supportvectormachine #python #learnpython #pythonprogramming #datascience #datamining #bigdata #datascienceworkshop #dataminingworkshop #dataminingtutorial #datasciencetutorial #ai #artificialintelligence #tutorial #dataanalytics #dataanalysis #machinelearningmodel #condainstall

КОМЕНТАРІ • 64

  • @DataProfessor
    @DataProfessor  4 роки тому +7

    Hi All,
    Big thanks to the viewers who had commented below about the interoperability of R and Python codes, please note that this video was a quick video to show that R and Python codes can co-exist in the same notebook. But for data interoperability, I will need to make a second video about this (which I am hard at work on, please stay tuned for this). By interoperability I mean that you can transfer data from R to Python and vice versa. Of particular note, the R magic command is running rpy2 Python library under the hood and there are other syntax not yet mentioned in this short video that can treat these R code as native Python code. Further information on this is provided at rpy2.github.io/doc/latest/html/notebooks.html
    (Note: Previous version of pandas used to have a function to import data from R directly into pandas, unfortunately this functionality was deprecated and is no longer available in the later versions).

    • @sumitsen922
      @sumitsen922 4 роки тому

      Dear Sir,
      When can we expect the interoperability video as currently I am working on the project in which I am generating the dataset from R but want to execute the ML models in python. Is there any reference I could use?

  • @KenJee_ds
    @KenJee_ds 4 роки тому +3

    Great content! I like some of the ggplot graphing features in R more than the ones in python. It is great to know that I can use them without changing workbooks!

    • @DataProfessor
      @DataProfessor  4 роки тому

      Thanks Ken for the support! Glad that it was helpful 😃

  • @importdata95
    @importdata95 4 роки тому +1

    This is awesome! Been using Google Colab for a while, but didn't know you could program in both languages in the same notebook. Thank you for the useful tip!

    • @DataProfessor
      @DataProfessor  4 роки тому +1

      Thanks Jaemin for the comment! Glad it was helpful. Did you know that you can also use native R right inside Google Colab, made a previous video about that ua-cam.com/video/huAWa0bqxtA/v-deo.html

    • @importdata95
      @importdata95 4 роки тому +1

      @@DataProfessor Yup! Already watched it haha!!

  • @GIOVANNYQUIA
    @GIOVANNYQUIA 4 роки тому +6

    Thanks a lot "Data professor" for your explanation, i have a question. How can i compute variables of the two language. for example if x=10 in python and y =15 in R. you know the process for do that x+y=25?

  • @UdayakumarBonagiri
    @UdayakumarBonagiri 2 місяці тому +1

    A big thanks to you. I could execute my R code in python notebook using your tip

  • @programmingseries436
    @programmingseries436 4 роки тому +2

    Can you cover how to connect input/output and variables from R and Python blocks?

  • @shwetaredkar734
    @shwetaredkar734 4 роки тому +1

    You are doing a fantastic job! 👍

  • @ahnaftahmidarnab6754
    @ahnaftahmidarnab6754 4 роки тому +1

    Thank you, Professor. You're a gem!

  • @kallolroy5029
    @kallolroy5029 3 роки тому +1

    Nicely explained Professor

  • @kirandeepmarala5541
    @kirandeepmarala5541 4 роки тому +1

    Crystal Clear,very well explained..Sir, I followed all your exploratory and Pandas tutorials..Very nice and learned a Lot.
    Sir, I want to do small Project of "Predicting the monthly rental of a house based on User Parameters", Till Now I learnt Pandas and Numpy.....Can you please Suggest What are the other things I have To Learn to complete end to end...Like which algorithm to learn all those things.....Please Help me....Finally you are doing Great to the community Each and every day...Keep it up

    • @shwetaredkar734
      @shwetaredkar734 4 роки тому +1

      You can start with Boston housing dataset. You will find many tutorials on this which will help you solve you problem statement.

    • @DataProfessor
      @DataProfessor  4 роки тому

      Marala, thanks for watching and for the kind comments! In fact, I've made a previous video on predicting house prices using the Boston data set at ua-cam.com/video/R15LjD8aCzc/v-deo.html and the codes are in the video description. I've also made a playlist on tutorial videos from this channel on Python end-to-end tutorials at ua-cam.com/video/XmSlFPDjKdc/v-deo.html

    • @kirandeepmarala5541
      @kirandeepmarala5541 4 роки тому +1

      @@shwetaredkar734 Thanks a lot..

    • @kirandeepmarala5541
      @kirandeepmarala5541 4 роки тому +1

      @@DataProfessor Thanks, for your support Sir, You are supporting your students within no times...From my bottom of my ♥..

    • @DataProfessor
      @DataProfessor  4 роки тому

      Marala Kirandeep Thanks for the kind words, please let me know what video topics you might want to see on this channel.

  • @omikawadhwa6616
    @omikawadhwa6616 3 роки тому +1

    Hello Professor, thank you for the video. Do you know how we can import a previously calculated python variable into the R environment to work with it there in colab?

  • @nastaranmarzban1419
    @nastaranmarzban1419 3 роки тому +1

    hi, hope you're doing well...thanks for your good explanations...I have one question, would you please answer me if possible? I really need it.
    If I get a result in R , fore example I have a = 2, can I save it and use it in the continuation of my program which will be done in python?
    thanks in advance

    • @DataProfessor
      @DataProfessor  3 роки тому

      Yes, that is possible for both R and Python where you can embed code from the other language into it. I would recommend to look into serializing your R or Python objects (pickle for Python or RDS for R)

  • @lightningblade9347
    @lightningblade9347 4 роки тому +2

    Awesome video! I have a question if you don't mind. How can I use a python package in an R notebook on Google Colab. the 'reticulate' package gives the ability to install a python library in R using 'py_install' but in Google Colab I get the error 'could not find a Python environment for /usr/bin/python3.' Is there a work around this error?

    • @DataProfessor
      @DataProfessor  4 роки тому +1

      Hi, I am encountering the same error as you had, I also have explored this and it seems that the R environment in colab does not have support for Python. The other way around is working fine (normal colab having reticulate installed).

  • @priya-ct6vm
    @priya-ct6vm 4 роки тому +2

    Hello Professor, thankyou for your videos....is there any way we can upload local files while running R in colab ?

    • @DataProfessor
      @DataProfessor  4 роки тому

      Yes you can click on the file icon found in the left panel to upload files by point and click. Please see this video “How to Upload Files to Google Colab” ua-cam.com/video/6HFlwqK3oeo/v-deo.html

  • @dspower7017
    @dspower7017 4 роки тому +1

    Great content!!, I was just curious to know whether the R inline codes are converted to python language syntax or processed as it is. I mean as I am r programmer whether I can directly go ahead using R codes if it doesn't impact the efficiency of the notebook. Thanks!

    • @DataProfessor
      @DataProfessor  4 роки тому

      Hi DS POWER, this video was a quick video to show that R and Python codes can co-exist in the same notebook. But for data interoperability, I will need to make a second video about this (which I am hard at work on, please stay tuned for this). Meaning that you can transfer data from R to Python and vice versa. The R magic command is running rpy2 Python library under the hood and there are other syntax not yet mentioned in this short video that can treat these R code as native Python code. Further information on this is provided at rpy2.github.io/doc/latest/html/notebooks.html
      Thank you for bring this up 😃

    • @dspower7017
      @dspower7017 4 роки тому +1

      That's great!

  • @muditarora9860
    @muditarora9860 3 роки тому

    any way I can install R for my jupyter kernel using pip and without Anaconda.
    Like I get new R file option in jupyter notebook kernel

  • @vaniedavystephanekouakoubi6369
    @vaniedavystephanekouakoubi6369 4 роки тому +1

    Thanks you very much

  • @madaragrothendieckottchiwa8648
    @madaragrothendieckottchiwa8648 4 роки тому +1

    Thank you data professor

    • @DataProfessor
      @DataProfessor  4 роки тому

      A pleasure, thank you for watching 😃

  • @Attack1086
    @Attack1086 4 роки тому +1

    Hi Chanin,
    Do you plan topics like time series analysis?
    Thank you.
    Regards,
    Teo

    • @DataProfessor
      @DataProfessor  4 роки тому +1

      Hi, thanks for the suggestion. I am not well versed with time series analysis but I can definitely look into this for future video.

  • @mark-d.rayleigh513
    @mark-d.rayleigh513 4 роки тому +1

    Thanks.
    Is there an also easy to handle option to run other Languages, which Jupyter can interpret, with an extern way for example Julia?
    It would be nice to juggle with data in one notebook. Mostly the practical way to colab in a firm is more a saving in some kind of format which other programmers can use, if it has to go fast. A data tunneling effect from kernel to kernel would be nice ;)

    • @DataProfessor
      @DataProfessor  4 роки тому +1

      This is a very good question! From my research, there is the SoS Notebook that can support several languages in the same Jupyter notebook. It supports R, Python 2/3, Julia, JS, etc. for more details, please see
      vatlab.github.io/sos-docs/doc/user_guide/multi_kernel_notebook.html

  • @egakurniayazid5651
    @egakurniayazid5651 4 роки тому +3

    Thank you! such great content. I wonder whether we can share a variable between R and Python? For instance, using python generated variable for the R ggplot2 visualization. Thanks in advance for any responses!

    • @DataProfessor
      @DataProfessor  4 роки тому

      Hi Yazid, yes you can share variables between R and Python. Have a look at this link where the answer shows how to plot the R library ggplot2 in python stackoverflow.com/questions/35152395/using-r-in-python-with-rpy2-how-to-ggplot2

  • @sebastiannastuta5043
    @sebastiannastuta5043 4 роки тому +1

    Is this working also in Jupyter Notebook or only in Google Colab? Thanks

  • @貫洞聖彦
    @貫洞聖彦 3 роки тому

    Thank you, Professor! If it were possible, please show us how to keep libraries downloaded in drive when using colab. Thanks.

  • @Wizhka
    @Wizhka 4 роки тому

    Gracias. Me ayudó bastante.

  • @learninglad9032
    @learninglad9032 2 роки тому

    After activating R magic and using %%R, I get the following error:
    NotImplementedError: Conversion 'py2rpy' not defined for objects of type ''
    Please help. Thanks

  • @caetanobernal4619
    @caetanobernal4619 4 роки тому

    Can you cover how to connect input/output and variables from R and Python blocks? is that possible:

  • @sergiomorellmonzo1780
    @sergiomorellmonzo1780 2 роки тому +1

    I'm not able to use this in Colab.
    import rpy2
    # activate R magic
    %load_ext rpy2.ipython
    I get the following error:
    NotImplementedError Traceback (most recent call last)
    in
    1 import rpy2
    2 # activate R magic
    ----> 3 get_ipython().run_line_magic('load_ext', 'rpy2.ipython')
    19 frames
    in load_ext(self, module_str)
    /usr/local/lib/python3.8/dist-packages/rpy2/robjects/conversion.py in _rpy2py(obj)
    250 non-rpy2) objects.
    251 """
    --> 252 raise NotImplementedError(
    253 "Conversion 'rpy2py' not defined for objects of type '%s'" %
    254 str(type(obj))
    NotImplementedError: Conversion 'rpy2py' not defined for objects of type ''
    How can I solve it?

  • @gadcastillo
    @gadcastillo 4 роки тому +1

    Do you know if it is possible to use esquisse in google Colab ?

    • @DataProfessor
      @DataProfessor  4 роки тому

      Hi Gabriel, thanks for the question. I did try in a native R notebook (in Google Colab), the installation was successful, loading in the library was successful, but upon using the command esquisser(iris), it attempts to spin up a local website "Listening on 127.0.0.1:5822" and upon clicking on that there was an error since with 127.0.0.1 as the address, the browser is expecting a local version of the website (which is on Colab). However, if you would like to run this on the cloud, you can try rstudio.cloud, it's free and it works just like the local version of RStudio.

    • @gadcastillo
      @gadcastillo 4 роки тому +1

      @@DataProfessor Thanks a lot I did try and got the same error! I am loving your channel. Your videos are short and to the point, easy to follow and to understand. Running both R and Python on Google Colab is just AMAZING! I ll chech RStudio Cloud! Thanks a lot and keep it up!

    • @DataProfessor
      @DataProfessor  4 роки тому

      @@gadcastillo Glad to be of help, let me know if it works 😃

    • @gadcastillo
      @gadcastillo 4 роки тому

      @@DataProfessor it does work! thank you!

  • @emiliabrasilio9111
    @emiliabrasilio9111 2 роки тому

    I had problem with py2rpy, but it's a version problem, then its necessary downgrade, using: "!pip install rpy2==3.5.1"

    • @emiliabrasilio9111
      @emiliabrasilio9111 2 роки тому

      After that, everything works amazing!! Thanks !! It helps me a lot.

  • @musicalwanderings7380
    @musicalwanderings7380 2 роки тому

    Use -i and -o args in %%R to pass data between python and R