2
$\begingroup$

So, let's start out by saying I am NOT asking which is better.

I like both of these languages for data science and I think this is a matter of and rather than or since there is no need to choose one of them. My general opinion is that R has more data science depth while Python has more breadth in terms of diversity of application.

I will start this out with a few of my own scattered opinions.

Python

I tend to use Python as the overarching language (sometimes using it to execute scripts in R) since:

Installed standard on Macs and many *nix setups Easy to install/set up in environments with security restrictions Has a great suite of tools whether I want to: Set up a website Interact with the Apache suite of tools Build out pipelines Build and score predictive models Develop an application / front-end Has a larger audience if I get stuck and need to ask questions on here Debug / Unit test Auto Document A good example of this was in building a Robot some facial recognition stuff over the summer. Raspbery Pi comes with Python by default, the sensors had Python API's, and a few of the web API's I bumped up against had Python API's available. This would have been a difficult application to take on using R.

R

I like to use R for early data explanation since data table tends to load larger sets into memory more quickly than Pandas and the general environment seems more mature for exploratory stuff. If I need mixed models or something similar that isn't Machine Learning "bread and butter" R is more likely to have what I need. sklearn is pretty good but doesn't feel quite as polished as what I have in R.

On the data viz side, ggplot2 is obviously better than matplotlib (the html based stuff is tough to share in an environment with heavy IP and security restrictions so I tend to lean towards the simple stuff.)

How do you use them?

How do you interact with these languages? Do you mix them together? Specialize in one? What's your rationale? Strengths/weaknesses?

$\endgroup$

1 Answer 1

7
$\begingroup$

Interaction - Random Facts

  1. Both are good stable languages with interesting complementary qualities. You can get much better packages in one and then stitch them with some data from the other. An example is using time series forecasting and decision trees in R and doing data munging in Python.

  2. Both languages borrow from each other. Even seasoned package developers like Hadley Wickham (Rstudio) borrows from Beautiful Soup (python) to make rvest for web scraping. In addition to that, Yhat borrows from sqldf to make pandasql and many other.

  3. Rather than reinvent the wheel in the other language developers can focus on innovation because, in the end, the customer does not care which language the code was written, the customer cares for insights.

Mixing Them Up

AM mentioning few approaches to mix them together-

  1. Use a Python package rpy2 to use R within Python . [Demo]

  2. Use Python from within R using the rPython package. [Demo]

  3. Use Jupyter with the IR Kernel. Python and R and makes the interactivity of iPython available to other languages.

  4. Use Beaker Notebook. It allows you to switch from one language in one code block to another language in another code block in a streamlined way to pass shared objects.

Python vs R

Python vs R - This section will answer:

  • Which will be better?
  • How to choose one over other?
  • Specialization

See as I said earlier both are stable and you can choose any or work with both. But when it comes to master one I'll suggest keep these 3-4 guidelines in mind-

Personal Preference

Choose the language to begin with based on your personal preference, on which comes more naturally to you, which is easier to grasp from the get-go. To give you a sense of what to expect, mathematicians and statisticians tend to prefer R, whereas computer scientists and software engineers tend to favor Python.

Project selection

You can also make the Python vs. R call based on a project you know you’ll be working on in your data studies. If you’re working with data that’s been gathered and cleaned for you, and your main focus is the analysis of that data, go with R. If you have to work with dirty or jumbled data, or to scrape data from websites, files, or other data sources, you should start learning, or advancing your studies in, Python.

Collaboration

Once you have the basics of data analysis under your belt, another criterion for evaluating which language to further your skills in is what language your teammates are using. If you’re all literally speaking the same language, it’ll make collaboration—as well as learning from each other—much easier.

Job market

Jobs calling for skill in Python compared to R have increased similarly over the last few years.

Note: Have a look at this infographic by DataCamp. For a better view on it.

My Rationale

In my case am doing both and using them interactively and Customizing them as per my use. You can get something really interesting in one (as I mentioned above) which will be hardly available in other, so it's better to use both together. This is the best way to bridge the gap between these two.

But in the last, it's your call keep the guidelines, your interest, and scenarios in mind and make a clear view on that.

Strength & Weaknesses

R

Strength

  • R is great for prototyping and for statistical analysis.
  • It has a huge set of libraries available for different statistical type analysis. Check The Comprehensive R Archive.
  • RStudio IDE is a definitely a big plus. It eases most of the tedious tasks and fastens your workflow.

Weaknesses

  • The syntax could be obscure sometimes.
  • It is harder to integrate to a production workflow.
  • In my opinion, it is better suited for consultancy-type tasks.
  • The libraries documentation isn't always user friendly.

Python

Strength

  • Python is great for scripting and automating your different data mining pipelines. It is the de facto scripting language nowadays.
  • It also integrates easily in a production workflow. Besides, it can be used across different parts of your software engineering team (back-end, cloud architecture etc.).
  • The scikit-learn library is awesome for machine-learning tasks.
  • Ipython (and its notebook) is also a powerful tool for exploratory analysis and presentations.

Weaknesses

  • It isn't as thorough for statistical analysis as R, but it has come a long way these recent years
  • In my opinion, the learning curve is steeper than R, since you can do much more with Python.

The Conclusion

Use R and Python. Learn how they inter-operate together. Start with one and then add the other to your workflow. As I like to remind myself- "choosing the tools should never be the primary problem". When in doubt, use the one that is available and that gets the work done quickly.

Hope it helps!

Ref- Udacity, Quora, Letustweak, kD, DataCamp

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.