<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r-and-python-how-to-integrate-the-best-of-both-into-your-data-science-workflow/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.business-science.io/business/2018/10/08/python-and-r.html"> business-science.io - Articles</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>From Executive Business Leadership to Data Scientists, we all agree on one thing: <strong><em>A data-driven transformation is happening</em></strong>. Artificial Intelligence (AI) and more specifically, Data Science, are redefining how organizations extract insights from their core business(es). We’re experiencing a fundamental shift in organizations in which <a rel="nofollow" href="http://www.visualcapitalist.com/the-rise-of-the-chief-data-officer-cdo/" target="_blank">“approximately 90% of large global organizations with have a Chief Data Officer by 2019”</a>. Why? Because, when the ingredients of a <strong><em>“high performance data science team”</em></strong> are present (<a rel="nofollow" href="https://www.business-science.io/business/2018/09/18/data-science-team.html" target="_blank">refer to this Case Study</a>), organizations are able to generate massive return on investment (ROI). However, data science teams tend to get hung up on a <em>“battle”</em> waged between the two leading programming languages for data science: <strong><em>R versus Python</em></strong>.</p>
<p><a rel="nofollow" href="https://www.business-science.io/business/2018/09/18/data-science-team.html" target="_blank"><img alt="Key Strengths, R and Python" src="https://i0.wp.com/www.business-science.io/assets/2018-09-18-data-science-team/amadeus_team.png?w=456" data-recalc-dims="1"></a></p>
<p>In our recent article, <a rel="nofollow" href="https://www.business-science.io/business/2018/09/18/data-science-team.html" target="_blank">“Case Study: How To Build A High Performance Data Science Team”</a>, we exposed how a real company (<a rel="nofollow" href="http://amadeusip.com/" target="_blank">Amadeus Investment Partners</a>) is utilizing a structured workflow that combines talented business experts, data science education, and a communication between subject matter experts and data scientists to achieve best-in-class results in the one of the most competitive industries: investing. One of the key points from this article was the use of data science languages as tools in a toolkit. R, Python… Use them both. Leverage their strengths. <strong><em>Don’t build an “R Shop” or a “Python Shop”. Build a High Performance Data Science Team that capitalizes on the unique strengths of both languages.</em></strong></p>
<blockquote>
<p><em>Don’t build an “R Shop” or a “Python Shop”. Build a <strong>High Performance Data Science Team</strong> that capitalizes on the unique strengths of both languages.</em></p>
</blockquote>
<p>This idea of using multiple languages may seem crazy. In the short term, it requires more education. But, in the long term it pays dividends in:</p>
<ol>
<li>
<p><strong>Increased efficiency</strong> (how quickly can your data science team iterate through its workflow)</p>
</li>
<li>
<p><strong>Increased productivity</strong> (how much can your data science team produce that adds value and generates ROI)</p>
</li>
<li>
<p><strong>Increased capability</strong> (how limited is your data science team’s output)</p>
</li>
</ol>
<h2>Summary</h2>
<p>This article is split into two parts:</p>
<ul>
<li>
<p><a rel="nofollow" href="http://www.business-science.io/business/2018/10/08/python-and-r.html#part1" target="_blank"><strong>Part 1: R + Python, Examination of Key Strengths</strong></a> – In this part we discuss the origins of the languages, key differences, and strengths that can be leveraged within a data science workflow</p>
</li>
<li>
<p><a rel="nofollow" href="http://www.business-science.io/business/2018/10/08/python-and-r.html#part2" target="_blank"><strong>Part 2: R + Python, Integrated Machine Learning Tutorial</strong></a> (<em>Alert: Technical Details Ahead</em>) – In this part we transition from planning to implementing the data science workflow using both R and Python.</p>
</li>
</ul>
<p>The strengths assessment concludes that both R and Python have amazing features that can interplay together. The visualization below summarizes the strengths.</p>
<p><img alt="Python and R Strengths" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/python_r_strengths.png?w=456" data-recalc-dims="1"></p>
<p><strong>Strengths Assessment, R and Python</strong></p>
<p>The ML Tutorial is particularly powerful showcasing the interplay between Python and R. You’ll end with a nice segment on model quality showing how to detect weaknesses in your model with <code>ggplot2</code>.</p>
<p><img alt="Residual Analysis" src="https://i1.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/residuals.png?w=456" data-recalc-dims="1"></p>
<p><strong>Model Evaluation</strong></p>
<p></p>
<hr>
<h2>You Need To Learn R For Business</h2>
<p><a rel="nofollow" href="https://university.business-science.io/p/hr201-using-machine-learning-h2o-lime-to-predict-employee-turnover/?product_id=635023&coupon_code=DS4B_15" target="_blank"><br>
<img alt="Data Science For Business With R Course" src="https://i2.wp.com/www.business-science.io/img/course_logo_full_DS4B_201_R.png?w=456" data-recalc-dims="1"><br>
</a></p>
<p><strong>To be efficient as a data scientist, you need to learn R.</strong> Take the course that has <strong>cut data science projects in half</strong> (see <a rel="nofollow" href="https://youtu.be/yw5CtGTzIw0" target="_blank">this testimonial</a> from a leading data science consultant) and has <strong>progressed data scientists more than anything they have tried before</strong>. Over 10-weeks you learn what it has taken data scientists 10-years to learn:</p>
<ul>
<li>Our systematic data science for business framework</li>
<li>R and H2O for Machine Learning</li>
<li>How to produce Return-On-Investment from data science</li>
<li>And much more.</li>
</ul>
<p>
<a rel="nofollow" href="https://university.business-science.io/p/hr201-using-machine-learning-h2o-lime-to-predict-employee-turnover/?product_id=635023&coupon_code=DS4B_15" target="_blank"><strong>Start Learning Today!</strong></a>
</p>
<p></p>
<hr>
<p></p>
<p>In this article, we’ll show a <strong>quick machine learning (ML) tutorial that integrates both R + Python, showcasing the strengths of the two dominant programming languages</strong>. But, before we get into the ML tutorial, let’s examine the strengths of each language.</p>
<h2>Part 1: R + Python, Examination of Key Strengths</h2>
<p>Both data science languages are great for business analysis. Both R and Python can be used in similar capacities when viewed from a pure machine learning perspective. Both have packages or libraries that are dedicated to wrangling, preprocessing, and applying machine learning to data. Both are excellent choices for <a rel="nofollow" href="https://en.wikipedia.org/wiki/Reproducibility" target="_blank">reproducibile research</a>, a requirement for many industries to validate research methodologies and experiments. Where things get interesting is their differences, which is the source of beauty and power of combining languages to work together in harmony.</p>
<p><a></a></p>
<p><img alt="Python and R Strengths" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/python_r_strengths.png?w=456" data-recalc-dims="1"></p>
<p><strong>Strengths Assessment, R and Python</strong></p>
<h3>R Strengths</h3>
<p>Let’s start with <code>R</code>. Well, actually, let’s start with <code>S</code>. The <code>S</code> language was a precursor to <code>R</code> developed by <a rel="nofollow" href="https://en.wikipedia.org/wiki/John_Chambers_(statistician)" target="_blank">John Chambers (statistician)</a> at Bell Labs in 1976 as a programming language designed to implement statistics. The <a rel="nofollow" href="https://en.wikipedia.org/wiki/R_(programming_language)" target="_blank">R statistical programming language</a> was developed by professors at the University of Auckland, New Zealand, to extend <code>S</code> beyond its initial implementation. The key point is that <code>S</code> and <code>R</code> developers were not software engineers or computer scientists. Rather, they were <strong>researchers and scientists that developed tools to more effectively design and perform experiments and communicate results</strong>.</p>
<p>In it’s essence, R is a language with roots in statistics, data analysis, data exploration, and data visualization. R has excellent utilities for reporting and communication including <code>RMarkdown</code> (a method for integrating code, graphical output, and text into a journal-quality report) and <code>Shiny</code> (a tool for building prototype web applications, think minimum viable products, MVP).</p>
<p>R is growing quickly with the emergence of the <code>tidyverse</code> (<a rel="nofollow" href="https://www.tidyverse.org/" target="_blank">tidyverse.org</a>), a set of tools with a common programming-interface that use functional verbs (functions like <code>mutate()</code> and <code>summarize()</code>) to perform intuitive operations connected by the pipe (<code>%>%</code>), which mimics how people read. <strong>The <code>tidyverse</code> is a big advantage because it makes exploring data highly efficient. Iterating through your exploratory analysis is as easy as writing a paragraph describing what you want to do to the data.</strong> Here’s a <code>tidyverse</code> flow chart from <a rel="nofollow" href="http://www.storybench.org/getting-started-with-tidyverse-in-r/" target="_blank">storybench.org</a>.</p>
<p><img alt="Tidyverse Workflow" src="https://i1.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/tidyverse.png?w=456" data-recalc-dims="1"></p>
<p><a rel="nofollow" href="http://www.storybench.org/getting-started-with-tidyverse-in-r/" target="_blank">Getting Started with tidyverse in R, storybench.org</a></p>
<p></p>
<p>The strengths of <code>R</code> relate very well to business wherein organizations need to test theories, explain cause-and-effect relationships, iterate quickly, and make decisions. Further, communication utilities including business reporting, presentation slide decks, and web applications can be built using a reproducible workflow all within <code>R</code>.</p>
<h3>Python Strengths</h3>
<p>The <code>Python</code> language is a general-purpose programming language that was created by <a rel="nofollow" href="https://en.wikipedia.org/wiki/Guido_van_Rossum" target="_blank">Guido van Rossum (Computer Scientist)</a> in 1991. The language was developed to be easy to read and cover multiple programming paradigms. One of it’s greatest strengths is <code>Python</code>’s versatility which includes web frameworks, data base connectivity, networking, web scraping, scientific computing, text and image processing, many of which features lend themselves to various tasks in machine learning including image recognition, natural language processing, and machine learning.</p>
<p><strong>In essence, <code>Python</code>’s roots are in computer science and mathematics.</strong> The language was designed for programmers that require versatility into many different fields. With over 100,000 open source libraries, <code>Python</code> has the largest ecosystem of any programming language, making it uniquely positioned as a choice for those that want versatility.</p>
<p><code>Python</code> has excellent data science libraries including <code>Scikit Learn</code>, the most popular machine learning library, and <code>TensorFlow</code>, a library developed by software engineers at Google to perform deep learning, commonly used for image recognition and natural language processing tasks. The <code>Scikit Learn</code> machine learning flow chart is shown below, which illustrates its reach for many types of machine learning problems.</p>
<p><img alt="Scikit Learn ML Flow Chart" src="https://i2.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/sklearn_ml_flowchart.png?w=456" data-recalc-dims="1"></p>
<p><a rel="nofollow" href="http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html" target="_blank">Scikit Learn Machine Learning Flow Chart, scikit-learn.org</a></p>
<p></p>
<p>In a business context, the key strength of <code>Python</code> rests in the powerful machine learning libraries including <code>Scikit Learn</code> and <code>TensorFlow</code> (and the <code>Keras</code> implementation, which is designed for efficiently building neural networks). The <code>Scikit Learn</code> library is easy to pick up, includes support for pipelines to simplify the machine learning workflow, and has almost all of the algorithms one needs in one place.</p>
<h3>Designing A Data Science Workflow</h3>
<p><strong>When you learn multiple languages, you gain the ability to select the best tool for the job.</strong> The result is a language harmony that increases the data science team’s efficiency, capability, and productivity.</p>
<blockquote>
<p><em>When you learn multiple languages, you gain the ability to select the best tool for the job.</em></p>
</blockquote>
<p>The general idea is to be as flexible as possible so we can leverage the best of both languages within our full-stack data science workflow, which includes:</p>
<ul>
<li>
<p>Efficiently exploring data</p>
</li>
<li>
<p>Modeling, Cross Validating, and Evaluating Model Quality</p>
</li>
<li>
<p>Communicating data science to make better decisions via traditional reports (Word, PowerPoint, Excel, PDF), web-based reports (HTML), and interactive web-applications (Shiny, Django)</p>
</li>
</ul>
<p>We can make a slight modification to the <a rel="nofollow" href="http://www.business-science.io/business/2018/10/08/python-and-r.html#strengths" target="_blank"><em>R and Python Strengths</em></a> visualization to organize it in a logical sequence that leverages the strengths:</p>
<ul>
<li>
<p>R is <strong>selected for exploration</strong> because of the <code>tidyverse</code> readability and efficiency</p>
</li>
<li>
<p>Python is <strong>selected for machine learning</strong> because of <code>Scikit Learn</code> machine learning pipeline capability</p>
</li>
<li>
<p>R is <strong>selected for communication</strong> because of the advanced reporting utilities including <code>RMarkdown</code> and <code>Shiny</code> (interactive web apps) and the wonderful <code>ggplot2</code> visualization package</p>
</li>
</ul>
<p><img alt="Python and R Workflow" src="https://i2.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/python_r_workflow.png?w=456" data-recalc-dims="1"></p>
<p><strong>Data Science Workflow Integrating R + Python</strong></p>
<p></p>
<p>Now that we have identified the tools we want to use, let’s go through a short tutorial that brings this idea of <strong>language harmony</strong> together.</p>
<p></p>
<hr>
<h2>Data Science For Business With R (DS4B 201-R) Course</h2>
<p>
Learn everything you need to know to complete a real-world, end-to-end data science project with the R programming language. Transform your abilities with our enterprise-grade 10-week system.
</p>
<p>
<a rel="nofollow" href="https://university.business-science.io/p/hr201-using-machine-learning-h2o-lime-to-predict-employee-turnover/?product_id=635023&coupon_code=DS4B_15" target="_blank"><strong>Start Learning Today!</strong></a>
</p>
<hr>
<p></p>
<h2>Part 2: R + Python, Integrated Machine Learning Tutorial</h2>
<p>The project we are performing comes from the <a rel="nofollow" href="https://elitedatascience.com/python-machine-learning-tutorial-scikit-learn" target="_blank">“Wine Snob Machine Learning Tutorial” by Elite Data Science</a>. We’ll perform the following:</p>
<ol>
<li>
<p>(Python) Replicate the Machine Learning tutorial using <code>Scikit Learn</code></p>
</li>
<li>
<p>(R) Use <code>ggplot2</code> to visualize the results for model performance</p>
</li>
<li>
<p>(R) Build the report using <code>RMarkdown</code> and the new <code>radix</code> framework for scientific reporting</p>
</li>
</ol>
<p>These are the same steps that were used to create the “Python + R with <code>reticulate</code>” report contained in this Machine Learning Tutorial on YouTube:</p>
<p><iframe allowfullscreen src="https://www.youtube.com/embed/YfqxICYVNtU" width="100%" height="450"></iframe></p>
<p>Python + R with Reticulate, YouTube Video</p>
<p>The report built in the video looks like this:</p>
<p><img alt="radix for web-based reports" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/report.png?w=456" data-recalc-dims="1"></p>
<p>Report with R and Python via <code>reticulate</code> and <code>radix</code></p>
<p>We’ll go through the basic steps used to build this “Python + R with reticulate” report in an <code>RMarkdown</code> document using both Python and R.</p>
<h3>Step 1: Setup R + Python Environments</h3>
<p>We’re going to do everything from the <a rel="nofollow" href="https://www.rstudio.com/products/rstudio/download/preview/" target="_blank">RStudio IDE: Preview Version</a>, which includes Python integration and interoperability.</p>
<p><img alt="RStudio IDE" src="https://i1.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/rstudio_ide.png?w=456" data-recalc-dims="1"></p>
<p><a rel="nofollow" href="https://www.rstudio.com/products/rstudio/download/preview/" target="_blank">RStudio IDE Preview Version (Required for Python Interoperability)</a></p>
<p>We’ll be using both R and Python Environments, which we’ll setup next.</p>
<h4>R Environment</h4>
<p><a rel="nofollow" href="https://rstudio.github.io/reticulate/index.html" target="_blank"><img alt="reticulate for connecting Python and R" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/reticulate.png?w=456" data-recalc-dims="1"></a></p>
<p>You’ll want to have the following libraries installed:</p>
<ul>
<li>
<p><code>reticulate</code>: Used to connect R and Python. See the <a rel="nofollow" href="https://rstudio.github.io/reticulate/index.html" target="_blank">reticulate documentation</a> which is an invaluable resource.</p>
</li>
<li>
<p><code>radix</code>: A new R package for making clean web-based reports. The <a rel="nofollow" href="https://rstudio.github.io/radix/" target="_blank">radix documentation</a> was built using <code>radix</code>.</p>
</li>
<li>
<p><code>tidyverse</code>: The fundamental set of R packages that makes data exploration and visualization easy. It includes <code>dplyr</code>, <code>ggplot2</code>, <code>tidyr</code> and more.</p>
</li>
<li>
<p><code>plotly</code>: Used to make a quick interactive plot with the <code>ggplotly()</code> function.</p>
</li>
<li>
<p><code>tidyquant</code>: Used for the <code>theme_tq()</code> ggplot theme for business-ready visualizations.</p>
</li>
</ul>
<h4>Python Environment</h4>
<p>You will need to have <code>Python</code> installed with the following libraries:</p>
<ul>
<li>
<p><code>numpy</code>: A numerical computing library that supports <code>sklearn</code></p>
</li>
<li>
<p><code>pandas</code>: Data analysis library enabling wrangling of data</p>
</li>
<li>
<p><code>sklearn</code>: Workhorse library with a suite of machine learning algorithms</p>
</li>
</ul>
<p>The easiest way to get set up is to download the <a rel="nofollow" href="https://www.anaconda.com/download" target="_blank">Anaconda distribution</a> of <code>python</code>, which comes with many of the data science packages already set up. If you install the Python 3 version of Anaconda, you should end up with a “conda environment” named <code>anaconda3</code>. We’ll use this in the next step.</p>
<p><img alt="Anaconda" src="https://i1.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/anaconda.png?w=456" data-recalc-dims="1"></p>
<p><a rel="nofollow" href="https://www.anaconda.com/download" target="_blank">Install Anaconda Distribution</a></p>
<h3>Step 2: Setup RMarkdown Document</h3>
<p>Open an RMarkdown document in the RStudio IDE.</p>
<p><img alt="Open A New RMarkdown Document" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/new_rmarkdown.png?w=456" data-recalc-dims="1"></p>
<p>Open a new RMarkdown document</p>
<p>Clear the contents, and add the following YAML header information including the <code>---</code> at the top and bottom. This sets up the <code>radix</code> document, which is a special format of <code>RMarkdown</code>. You can visit the <a rel="nofollow" href="https://rstudio.github.io/radix/" target="_blank">radix documentation</a> to learn more about it’s excellent features for web-based reports.</p>
<div>
<div>
<pre><code>---
title: &quot;R + Python via reticulate&quot;
description: |
  Taking the `radix` R package for a test spin with `Scikit Learn`!
author:
  - name: Matt Dancho 
    url: www.business-science.io
    affiliation: Business Science
    affiliation_url: www.business-science.io
date: &quot;2018-10-08&quot;
output: radix::radix_article
---
</code></pre>
</div>
</div>
<p>Next, add an R-code chunk.</p>
<p><img alt="R Code Chunk" src="https://i1.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/r_chunk.png?w=456" data-recalc-dims="1"></p>
<p>Adding an R-Code Chunk to an RMarkdown document</p>
<p>This will setup the defaults to output code chunks and toggle off messages and warnings.</p>
<div>
<div>
<pre><code>{r setup, include=FALSE}
knitr::opts_chunk$set(
    echo = TRUE,      # Output code chunks
    message = FALSE,  # Toggle off message output 
    warning = FALSE)  # Toggle off warning output
</code></pre>
</div>
</div>
<p>Next, if you hit the “Knit” button, the Radix report will generate. It should look something like this.</p>
<p><img alt="Open A New RMarkdown Document" src="https://i0.wp.com/www.business-science.io/assets/2018-10-08-python-and-r/step_02.png?w=456" data-recalc-dims="1"></p>
<p>Step 2, Radix Report</p>
<h3>Step 3: Setup Reticulate</h3>
<p>Reticulate connects R and Python Environments so both languages can be used in the RMarkdown document. For the purposes of keeping the languages straight, each code chunk (code that runs inline in an RMarkdown document) will have the language as a comment.</p>
<p>The code chunks <em>won’t</em> be shown in full but the contents will. When going through the tutorial use the <code>#R</code> and <code>#Python</code> comments to indicate which type of code chunk to use (i.e. <code>{r}</code> for R and <code>{python}</code> for Python).</p>
<p>Create an R-code chunk to load <code>reticulate</code> using the <code>library()</code> function.</p>
<figure>
<pre><code data-lang="r"><span># R</span><span>
</span><span>library</span><span>(</span><span>reticulate</span><span>)</span></code></pre>
</figure>
<p>Use the <code>conda_list()</code> function to list each of the environments on your machine. There are four present for my setup. I’ll be using the <code>anaconda3</code> environment.</p>
<figure>
<pre><code data-lang="r"><span># R</span><span>
</span><span>conda_list</span><span>()</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">##           name                                  python
## 1    anaconda3                   /anaconda3/bin/python
## 2       pandas       /anaconda3/envs/pandas/bin/python
## 3 r-tensorflow /anaconda3/envs/r-tensorflow/bin/python
## 4    untitled1    /anaconda3/envs/untitled1/bin/python</code></pre>
</figure>
<p>Tell <code>reticulate</code> to use the “anaconda3” environment using the <code>use_condaenv()</code> function.</p>
<figure>
<pre><code data-lang="r"><span># R </span><span>
</span><span>use_condaenv</span><span>(</span><span>&quot;anaconda3&quot;</span><span>)</span></code></pre>
</figure>
<p><img alt="Open A New RMarkdown Document" src="http://www.business-science.io/business/2018/10/08/%22/assets/2018-10-08-python-and-r/step_03"></p>
<p>Step 3, Radix Report</p>
<h3>Step 4: Machine Learning With Scikit Learn</h3>
<p>This step comes straight from the <a rel="nofollow" href="https://elitedatascience.com/python-machine-learning-tutorial-scikit-learn" target="_blank">“Wine Snob Machine Learning Tutorial” by Elite Data Science</a>. We’ll implement <code>Scikit Learn</code> to build a random forest model on that predicts the Wine Quality of the dataset.</p>
<p>First, create a Python code chunk and add the libraries.</p>
<figure>
<pre><code data-lang="python"><span># Python</span>
<span>import</span> <span>numpy</span> <span>as</span> <span>np</span>
<span>import</span> <span>pandas</span> <span>as</span> <span>pd</span>
<span>from</span> <span>sklearn.model_selection</span> <span>import</span> <span>train_test_split</span>
<span>from</span> <span>sklearn</span> <span>import</span> <span>preprocessing</span>
<span>from</span> <span>sklearn.ensemble</span> <span>import</span> <span>RandomForestRegressor</span>
<span>from</span> <span>sklearn.pipeline</span> <span>import</span> <span>make_pipeline</span>
<span>from</span> <span>sklearn.model_selection</span> <span>import</span> <span>GridSearchCV</span>
<span>from</span> <span>sklearn.metrics</span> <span>import</span> <span>mean_squared_error</span><span>,</span> <span>r2_score</span>
<span>from</span> <span>sklearn.externals</span> <span>import</span> <span>joblib</span></code></pre>
</figure>
<p>Next, import the data using <code>read_csv()</code> from <code>pandas</code>. Note that the separator is a colon (not a comma which is what most data sets are stored as in CSV format). The data is stored as a Python object named <code>data</code>.</p>
<figure>
<pre><code data-lang="python"><span># Python</span>
<span>dataset_url</span> <span>=</span> <span>'http://mlr.cs.umass.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv'</span>
<span>data</span> <span>=</span> <span>pd</span><span>.</span><span>read_csv</span><span>(</span><span>dataset_url</span><span>,</span> <span>sep</span> <span>=</span> <span>&quot;;&quot;</span><span>)</span></code></pre>
</figure>
<p>We can use the <code>print()</code> function to output Python objects.</p>
<figure>
<pre><code data-lang="python"><span># Python</span>
<span>print</span><span>(</span><span>data</span><span>.</span><span>head</span><span>())</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">##    fixed acidity  volatile acidity   ...     alcohol  quality
## 0            7.4              0.70   ...         9.4        5
## 1            7.8              0.88   ...         9.8        5
## 2            7.8              0.76   ...         9.8        5
## 3           11.2              0.28   ...         9.8        6
## 4            7.4              0.70   ...         9.4        5
## 
## [5 rows x 12 columns]</code></pre>
</figure>
<p>Note that it’s a little tough to see what’s going on with the data. It’s a perfect opportunity to leverage R and specifically the <code>glimpse()</code> function. We can retrieve the <code>data</code> object, which is stored in our R environment in a list named <code>py</code>. We’ll access <code>data</code> in R using <code>py$data</code>.</p>
<p>Load the <code>tidyverse</code> library. Then access the <code>data</code> object using <code>py$data</code>. The data is stored as a data frame, so we’ll convert to the <code>tibble</code> (tidy data frame) and then <code>glimpse()</code> the data.</p>
<figure>
<pre><code data-lang="r"><span># R</span><span>
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>py</span><span>$</span><span>data</span><span> </span><span>%>%</span><span> </span><span>as.tibble</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>glimpse</span><span>()</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## Observations: 1,599
## Variables: 12
## $ `fixed acidity`        </code></pre></figure>