<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/exploratory-analysis-when-to-choose-r-python-tableau-or-a-combination/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.stoltzmaniac.com/tool-selection-python-tableau-r/"> R-Projects – Stoltzmaniac</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>Not all data analysis tools are created equal.</h3>
<p>Recently, I started looking into data sets to compete in <a rel="nofollow" href="http://gocode.colorado.gov/" target="_blank">Go Code Colorado</a> (check it out if you live in CO). The problem with such diversity in data sets is finding a way to quickly visualize the data and do exploratory analysis. While tools like Tableau make data visualization extremely easy, the data isn’t always properly formatted to be easily consumed. Here’s are a few tips to help speed up your exploratory data analysis!</p>
<p>We’ll use data from two sources to aid with this example:</p>
<ul>
<li><a rel="nofollow" href="https://codataengine.milesmedia.com/api/feeds/events" target="_blank">Weekly events in Colorado</a> (XML)</li>
<li><a rel="nofollow" href="https://data.colorado.gov/Demographics/Census-Zip-Codes-in-Colorado-2016/rwak-e74e" target="_blank">Census data for Colorado</a> (JSON, ShapeFile)</li>
</ul>
<h4>Picking the right tool</h4>
<p>Always be able to answer the following before choosing a tool:</p>
<p><span></span></p>
<ol>
<li>How is your data stored? Is your data stored as JSON, XML, in a SQL/Relational Database, etc.?</li>
<li>Are you allowed to use the data? Do you have credentials? Is it proprietary?</li>
<li>Is it safe? Is it secure?</li>
<li>Does it need to be updated? If so, how frequently? Is it streaming?</li>
<li>What do you expect from exploratory analysis? Do you need a map, charts and/or tables?</li>
</ol>
<h3>When to use Tableau</h3>
<p>Tableau has amazing out of the box connection capabilities. It can immediately consume multiple file types, connect to multiple types of databases and has pre-built connections to multiple services. Due to this flexibility, it’s almost always my first choice.</p>
<div class="wp-caption"><img sizes="(max-width: 515px) 100vw, 515px" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2018/03/Screen-Shot-2018-03-10-at-11.49.06-AM.png?w=450" alt="" class="wp-image-652" data-recalc-dims="1">
<p class="wp-caption-text">Tableau – out of the box data connectors</p>
</div>
<p>Use it if you have geospatial data types! It really saves you a lot of time because it handles longitude/latitude (or creates it based off of addresses) and maps everything incredibly easily.</p>
<p>It easily handles our ShapeFile (.shp) and makes mapping incredibly easy. All you have to do is drag and drop, the rest is taken care of for you!</p>
<div class="wp-caption"><img sizes="(max-width: 2232px) 100vw, 2232px" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2018/03/Screen-Shot-2018-03-11-at-12.42.18-PM.png?w=450" alt="" class="wp-image-658" data-recalc-dims="1">
<p class="wp-caption-text">Tableau – ShapeFiles made easy</p>
</div>
<h3>When to avoid Tableau</h3>
<p>I find trouble using Tableau with nested data sources, NoSQL databases, web scraping, and anything requested via https. It simply isn’t built for a lot of these things. The team has made a lot of upgrades in this department, but you will spend way too much time figuring out how to get your data into a usable format.</p>
<p>However, it isn’t free (and certainly isn’t cheap). Microsoft Power BI can be a great choice if you don’t have Tableau but doesn’t have quite as robust functionality in my opinion.</p>
<p>Our XML data is an example that simply cannot be read by Tableau (greyed out below):</p>
<div class="wp-caption"><img sizes="(max-width: 1318px) 100vw, 1318px" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2018/03/Screen-Shot-2018-03-10-at-12.21.48-PM.png?w=450" alt="" class="wp-image-653" data-recalc-dims="1">
<p class="wp-caption-text">Cannot select XML file using “more”</p>
</div>
<p>Our JSON data is nested in a way that it becomes difficult to interpret and use easily in Tableau. If you dig deep enough, there may be a way to get the results you’re looking for but it’s not a trivial task.</p>
<div class="wp-caption"><img sizes="(max-width: 1357px) 100vw, 1357px" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2018/03/Screen-Shot-2018-03-10-at-12.53.24-PM.png?w=450" alt="" class="wp-image-656" data-recalc-dims="1">
<p class="wp-caption-text">Tableau with nested JSON</p>
</div>
<h3>When to use R</h3>
<p>Typically, my next thought is to pull data into R. Due to the open source nature of R and its popularity in the data science world, you can usually find a way to connect with almost any data source! If you’re connecting to data online, you are able to use <code>RCurl</code> in order to make requests. Almost all filetypes and databases are supported with a library (.xml = <code>library(&quot;XML&quot;)</code> , .json = <code>library(&quot;jsonlite&quot;)</code> …). You can also find a lot of libraries developed for popular API’s, for example, Mark Edmonson’s <code>RGoogleAnalytics</code>.</p>
<p>R also has amazing data wrangling libraries such as <code>ggplot2</code> , <code>dplyr</code> , and <code>tidyr</code> (Hadley Wickham’s <code>tidyverse</code>). These libraries have revolutionized how data manipulation and visualization is done. Code is easy to read, easy to write and usually works flawlessly.</p>
<p>Looking at our XML file, we can easily read it from the web with <code>RCurl</code> and parse the data using the <code>XML</code> library. From there, everything is easily accessible by using indices and the <code>$ operator</code>.</p>
<div class="wp-caption"><img sizes="(max-width: 620px) 100vw, 620px" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2018/03/Screen-Shot-2018-03-11-at-12.48.58-PM-866x1024.png?w=450" alt="" class="wp-image-659" data-recalc-dims="1">
<p class="wp-caption-text">Parsing R with XML</p>
</div>
<p>You will also notice that I use RStudio. It has phenomenal functionality and is the best IDE for R (nothing even comes close). You can explore your data in a table view, and even nested objects can be drilled down into so you can see the data’s structure.</p>
<p>R also integrates with Tableau (and Power BI for that matter)! While it’s not the most intuitive or user-friendly, it consistently gets better and is becoming more powerful because you can integrate bleeding-edge machine learning technology or customize algorithms to build better models.</p>
<h3>When to avoid R</h3>
<p>This is a sensitive topic in the data science world and is very subjective. However, I recommend avoiding R when you have to clean the data before storing it. For example, scraping a website for multiple days in order to build a data set for analysis. While this can be done using <code>RCurl</code> and <code>RVest</code> (another phenomenal library), it tends to be more difficult and time consuming than using libraries in Python which tend to be built for automation (such as <code>scrapy</code>). In reality, I don’t deal with data which cannot be consumed easily in R.</p>
<p>Another big concern people have is using “big data” with R because everything is stored in memory, however, in exploratory analysis I hope you aren’t pulling in that much data. If you are, try a subset in order to get an idea of what you’re dealing with.</p>
<h3>When to use Python</h3>
<p>This is typically my third option and I use it least in data exploration but the most in production environments. One of the biggest advantages with Python is when sharing exploration with a group of people. Using virtual environments is easy, fast and dependable. With a simple line of code: <code>pip install -r requirements.txt</code> you will ensure that the packages you use are the same as the author’s (be careful, it doesn’t ensure that you’re using the same version of Python). If reproducibility is important to you, Python is where it’s at.</p>
<p>Python is also great at handling streaming data. If you need “real-time” data, you’re going to do well with Python. CERN and NASA deal with a lot of streaming data (in huge volumes) and utilize Python!</p>
<p>Another great reason to use Python is if you have obscure data types. With such a large user base, chances are, someone has built a package to help you parse your data. Using a package will save you time, trouble and money.</p>
<h3>When to avoid Python</h3>
<p>Don’t use Python if you need to do quick, out of the box data visualization. Simply put, it’s extremely frustrating and difficult to get a nice graph, chart, or map. While matplotlib has been expanded upon with <code>seaborn</code> and a number of other tools, most lack instant gratification and require you to do a lot of customization. Fortunately, they are starting to catch up and I’m sure this will not be a problem for too much longer.</p>
<h3>When to mix and match Python, R, and Tableau</h3>
<p>At this point, you are probably able to guess when to mix and match. To be effective, start thinking through how your data is acquired, what the final output should look like and what transformations you will need to get there!</p>
<p>Let’s make up a random example that would be perfect for such a combination. Let’s say that you want to compare articles from the homepage of Fox News and CNN over the period of a month. How would you go about exploratory analysis? One possible workflow could be:</p>
<ol>
<li>Use Python to scrape the data regularly and store it in a database (using <code>scrapy</code> or <code>newspaper</code>)</li>
<li>Use R to get the data into a tidy format for analysis (using <code>tidytext</code>) and then write the results to a csv file</li>
<li>Use Tableau to visualize the results (and perhaps even utilize models from R to determine sentiment and analyze keywords)</li>
</ol>
<p>For the next post, perhaps I’ll build that out and see if it’s as simple as 1, 2, 3!</p>
<p>Also, if anyone who works for Tableau happens to be reading this, <em><strong>please make a connector to SQLite databases</strong></em>! It’s really frustrating not having that functionality.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.stoltzmaniac.com/tool-selection-python-tableau-r/"> R-Projects – Stoltzmaniac</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/1rcYbJo_gXY" height="1"></a></div>