<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Beto Rendon on Medium]]></title>
        <description><![CDATA[Stories by Beto Rendon on Medium]]></description>
        <link>https://medium.com/@humbertorendonr?source=rss-a9058ad894b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pIXqHKlSKbQMjpQx7xdh5A.png</url>
            <title>Stories by Beto Rendon on Medium</title>
            <link>https://medium.com/@humbertorendonr?source=rss-a9058ad894b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:47:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@humbertorendonr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Embracing the Rollercoaster: The Magic Behind Variation]]></title>
            <link>https://medium.com/byte-sized-data/embracing-the-rollercoaster-the-magic-behind-variation-1820dc2c14da?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1820dc2c14da</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-literacy]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Mon, 22 May 2023 15:01:51 GMT</pubDate>
            <atom:updated>2023-05-22T15:01:51.177Z</atom:updated>
            <content:encoded><![CDATA[<h4>Is randomness really out of our control?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-zHME67JQLD6i0M8t4KIg.png" /></figure><p>Variation is our daily driver. Stock markets crash and burn or they go to the moon, your favorite politician is today’s favorite and tomorrow’s most hated. Every aspect of our lives is affected by variation. Is that scary or is it fun?</p><p>Just like with everything else, at some point we just accept that’s how things will be. Even though we can’t really explain the reason for every change, it becomes routine. We accept this constant change <em>as long as it makes sense to us</em>. <a href="https://medium.com/byte-sized-data/unleashing-the-statistical-detective-within-questioning-data-strengthening-intuition-a2621f5e018d">But it gets complicated when we</a> are close to the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yoHwR7A8ozzOODEfcn7qng.gif" /></figure><p>Businesses change every day, week, month, quarter and year. One day a company could be the industry leader, and next day they throw out a divisive marketing campaign. Customers might be devoted fans, and then become determined boycotters. This is normal.</p><p>When we accept change as a constant, we don’t really need to explain every single up and down. We know the seesaw goes up and down. It would be strange if it went sideways. Only then should we actually be interested in finding out why. But usually businesses still care about explaining the all too familiar change.</p><blockquote>Why did sales plummet? Why did sales grow? What did we do during that week? OK do more of that and less of this. Variation is scary because it brings uncertainty, so we try to feel in control however we can (even though there are things we can’t change).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDPTtsTsbCBDVCvdbTrVqA.gif" /></figure><p>There are two types of variation. One comes from the way data was collected (measurement variation), and the other comes from the randomness of the process itself (random variation).</p><p>This is more important than you think. I know it sounds kind of boring and useless, but this opens the question <strong>“Are the decisions being made based on random variation, or is the variation based on an underlying process?”</strong>. This is suuuuper important because it determines if the variation we’re dealing with is under our control or not. If it’s just random, well then what can we do, but if it’s not, we definitely can control the measuring processes.</p><p>For obvious reasons we’ll always want the latter. But if it’s not so obvious why, imagine going to a casino. You play blackjack and feel hopeless when you lose money because “Well I can’t really control luck, can I?”. But then you realize that the variation can be controlled by counting cards. Now imagine those savings/earning, but for a company (millions of dollars instead of thousands).</p><blockquote>The only constant, is change</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1820dc2c14da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/embracing-the-rollercoaster-the-magic-behind-variation-1820dc2c14da">Embracing the Rollercoaster: The Magic Behind Variation</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unleashing the Statistical Detective Within: Questioning Data & Strengthening Intuition]]></title>
            <link>https://medium.com/byte-sized-data/unleashing-the-statistical-detective-within-questioning-data-strengthening-intuition-a2621f5e018d?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2621f5e018d</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistical-analysis]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Tue, 16 May 2023 00:29:21 GMT</pubDate>
            <atom:updated>2023-05-16T00:29:21.452Z</atom:updated>
            <content:encoded><![CDATA[<h4>Develop your spider-sense for suspicious data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nr1y7h6wg20jMkxuOcqxQw.png" /></figure><p>Remember when we were kids and we couldn’t stop asking questions? Well, believe it or not, that’s a core tenet of statistical thinking. Many of us are still like that. Even if you think you’re not, you probably still have some of it somewhere in your subconscious mind.</p><blockquote>Every time you question a claim based on data, like “Earn $500 a day with this simple method” or “Lose 10 pounds a week with this secret!”, that statistical thinker is screaming to get out.</blockquote><p>It’s easier being the critic than being the contestant. It’s all fun and games tearing obvious lies from afar, but it’s not so fun when it actually matters to us. Remember last election? How suspicious were you of <em>the other </em>party’s data? Because I bet you weren’t as critical as with the party you supported.</p><p>The point here, is that it’s hard to play detective when your mom is the suspect. A data driven mind questions everything, but that’s extremely hard to do when that “everything” includes your own identity and reasoning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iy8Nl4lEQrmj3rY2tS9Sw.png" /></figure><p>This becomes much more relevant when we take it to the workplace. When we are at work, we see a whole lot of data (reports, presentations, etc.), yet for some reason we rarely question it. An excel report with weird quantities? Count me in! A presentation with mysterious quarterly earnings? Don’t mind if I do.</p><p>Usually these documents are seen as facts, and I pity the fool who questions them because he might annoy the manager and be seen in a bad light. The problem is that this is the one place where questioning the data helps everyone. It might be annoying to have to double check or investigate again, but doing so might save time and resources, which would benefit everyone in the long run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Q_atH9SRVRxlFRzTJpWpw.png" /></figure><p>There’s a myriad of reasons why problems like this might occur. Political reasons like the one I just mentioned. Working under pressure might also instinctively urge you to trust the data. Even long chains of assumptions might occur, where one person assumes a number is correct and passes it on, and the next person assumes that the person before had everything in check, and so on.</p><p>I understand it’s not easy to constantly analyze data when the clock is ticking, but having the sense the data is not always right just because it’s on a spreadsheet will strengthen your intuition. If you keep this skepticism, in the long run you’ll be able to <strong>sense </strong>when something is wrong.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2621f5e018d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/unleashing-the-statistical-detective-within-questioning-data-strengthening-intuition-a2621f5e018d">Unleashing the Statistical Detective Within: Questioning Data &amp; Strengthening Intuition</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The ABCs of Summary Stats: Mean, Median, and Mode]]></title>
            <link>https://medium.com/byte-sized-data/the-abcs-of-summary-stats-mean-median-and-mode-36487cb1fa6f?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/36487cb1fa6f</guid>
            <category><![CDATA[data-literacy]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 19:10:54 GMT</pubDate>
            <atom:updated>2023-04-26T19:10:54.296Z</atom:updated>
            <content:encoded><![CDATA[<h4>Making Sense of Data with Mean, Median, and Mode</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzDco5gptiYrOsD4MqiFyQ.png" /></figure><p>Data doesn’t always look like a squeaky clean spreadsheet. Most of the times it comes as some form of summary statistics. If you don’t know what that means, let me give you a brief example. Let’s say you download a dataset about movies. Instead of looking through the whole dataset and trying to infer things, with summary statistics you could quickly learn that most of last year movies sucked. The most common summary statistics are <strong>mean</strong>, <strong>median</strong>, and <strong>mode</strong> (yes, here we go again).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mz3ihUvZRNYZbe3n7NVukA.png" /></figure><h4>Mean (average)</h4><p>The sum of all the numbers, divided by the count of all your numbers. The purpose of the mean is to give you a sense of what every number as an individual contributes to the whole series.</p><p>For example, let’s say you have to give a presentation about selling lemonade at your younger brother’s school. You ask your brother for the ages of the people who are going to be there, and he tells you ages from 7 to 9. You could count and consider every age individually, but you know that <strong>on average </strong>you’ll be talking to 8 year old kids, so you end up simplifying your presentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*noi4CDubG0qGqL83dSLUIw.png" /></figure><h4>Median</h4><p>The median is the midpoint of your data. Getting the median is very important because it’s less sensitive to outliers than the <strong>mean</strong>. But what does this mean? (ba dum tss) This means that if you have extreme values in your data, you won’t go in the wrong direction.</p><p>For example, let’s say you’re looking at salaries in a company. If there’s an employee with a very high salary, getting the average will make you think everybody else’s salary is higher than it actually is. But if you use the median, this mythical high earner won’t affect everyone else’s salary.</p><blockquote>Remember that to get the median, the data has to be in order</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgPEveWy0N2ZW5VIu4LztA.gif" /></figure><h4>Mode</h4><p>The most common number in the dataset. If every number in your dataset repeats the same amount of times, then we can say that there is no mode. Knowing the mode can help us identify outliers and it’s specially useful with categorical data (when there is no particular order).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4B01FRjSMiJpdtdRiTjZew.gif" /></figure><h4>Common Misconceptions</h4><p>Even though these are basic statistics, sometimes we are still silly billies. For example, let’s say we have the numbers 1, 2, 3, 3, 3, 2, 1, 2, 1, 3, 100. The <strong>mean</strong> would say that our average is 11. This number not only doesn’t appear in our data, but it’s far from what we might find in that dataset. The <strong>median</strong> on the other hand would say that the middle point of our data is 2, which makes sense considering most of our numbers are 1, 2 and 3. The <strong>mode</strong> would tell us that the most common number is 3, which also makes sense. This is a very simple example, but it gets weird with real data.</p><p>What would you understand if I told you that the average number of people in a household is 2.5? It’s very common for people to use the average as the midpoint, because I guess it’s “intuitive” (half of the numbers must be below and half above). When using these measures, always second-check the logic behind your findings.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36487cb1fa6f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/the-abcs-of-summary-stats-mean-median-and-mode-36487cb1fa6f">The ABCs of Summary Stats: Mean, Median, and Mode</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observational Vs Experimental Data: What’s The Difference?]]></title>
            <link>https://medium.com/byte-sized-data/observational-vs-experimental-data-whats-the-difference-597e3fc81f74?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/597e3fc81f74</guid>
            <category><![CDATA[data-literacy]]></category>
            <category><![CDATA[data-scientist]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Fri, 21 Apr 2023 15:02:14 GMT</pubDate>
            <atom:updated>2023-04-21T15:02:14.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-f3oRAXx3vzeA1sZxZYow.jpeg" /></figure><p>In a <a href="https://medium.com/@humbertorendonr/data-types-unplugged-80ef406ce204">previous article</a> we talked about data types in a dataset, but there’s more to it than that. In this article we’ll talk about how data is collected and how it’s structured.</p><p>Depending on how data is collected, we can describe it as <strong>observational</strong> or <strong>experimental</strong>. Understanding the difference is important because it it impacts how we interpret and analyze the data. When we don’t understand the difference, we end up making common mistakes (i.e. correlation ≠ causation). If we want to be serious about working with data (specially as data scientists or statisticians), we have to be serious about the methods for collecting data.</p><h3>Observational Data</h3><p>Observational data is collected through (you guessed it) observation. This means that anything that can be heard or seen is collected. Hearing and seeing also applies to computers (i.e. website trackers).</p><p>It’s very likely that most of the data in your company is observational. Mostly because it’s easier to obtain. If you’re already generating data, why not store it right? Observational data is the easiest to collect (and it’s free).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9uxunh-lqTzzxdNrGrwBDQ.gif" /></figure><p>Observational data might be things like website data (visits, clicks, time spent on site, etc.), sales, emails, number of calls, etc. Most of the times this data is stored for a reason (we might not know how to analyze sales data, but we know its important enough to store it), but there are cases where we collect data without a specific reason (we don’t know how to use it now, but it might come in handy later).</p><p>Observational data can also be called <strong>found data</strong>. Although found data is referring mostly to data that is a byproduct of other things. For example, a social media post is data by itself, but if we could also collect the relationships found in that post (with other users, pages, etc.), we would also have <strong>found data</strong>.</p><h3>Experimental Data</h3><p>Experimental data is a tougher cookie. It’s collected by doing experiments through the scientific method with a prescribed methodology. This means that experimental data <strong>is not passively collected</strong>.</p><blockquote>That sounds like a mouthful, but it’s basically doing experiments to get data</blockquote><p>Experimental data is collected for a specific purpose or question. You just don’t stumble upon it. That’s why it’s the Wagyu Beef of statisticians and data scientists. The thing is, that just like Wagyu Beef, it’s also harder and more expensive to collect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSTg_LQPqLt60Ef17qZhgw.gif" /></figure><p>A treatment must be randomly assigned to something (to avoid any bias that might make the data unreliable). Depending on what the experiment is about, guidelines to collect the data might change, but in essence they will all have the purpose to increase reliability. Common mistakes with experimental data include not controlling for confounding variables, small sample sizes and using the wrong statistical tests.</p><p>Clinical drug trials would be a classic example. Remember how they always split the patients into groups, and one group is given placebos? Well, it’s part of increasing reliability. Patients are chosen based on similar characteristics and without diseases to get the best possible “clean slate”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=597e3fc81f74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/observational-vs-experimental-data-whats-the-difference-597e3fc81f74">Observational Vs Experimental Data: What’s The Difference?</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Escape Tutorial Hell]]></title>
            <link>https://medium.com/byte-sized-data/how-to-escape-tutorial-hell-8e5a93f6f07f?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e5a93f6f07f</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[tutorial-hell]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 15:02:13 GMT</pubDate>
            <atom:updated>2023-04-20T15:02:13.289Z</atom:updated>
            <content:encoded><![CDATA[<h4>The best strategy to create a healthy relationship with tutorials</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujEv_8V5aJrWDbeubdxlwg.png" /></figure><h3>What is tutorial hell?</h3><p>Tutorial hell is the place where happy developers go to die. It’s the never ending pit of books, courses and videos. Instead of working on a real-life project or a personal project, you keep following tutorials. It’s that place where you spend hours watching a tutorial, but then when you try on your own, you’re back to square one.</p><blockquote>We’ve all been there, the point is not staying there.</blockquote><h3>How do I get out?</h3><p>The best way is by asking questions. We might get a little philosophical, but asking questions will naturally reveal your blind spots, while also giving you the next step to take.</p><p>Instead of thinking in terms of “tutorials”, think in terms of “projects”. When learning a new technology or tool, visualize a project. Once you clearly define a project in your mind, think of it as an end goal, which will later be broken down into smaller pieces.</p><p>For example let’s say we want to analyze weather data with Python (the project can be about anything, but I’m a data guy so.. 🤷🏻). First we need to visualize how our analysis will look like and what will it answer. Then we start asking questions like:<br> — How do I install Python?<br> — How do I run it in VS Code?<br> — What is a package?<br> — How do I install Pandas?<br> — How do I import a CSV?</p><p>Not knowing the answers is part of the game. We’ll probably need to google or ask chat gpt about it. I can confidently say that, asking and building will give a much higher return than following tutorials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pLEnsdBvAwV6TjSl3LTcA.gif" /></figure><h4>Focus on small projects</h4><p>When learning something we might get desperate to show off our skills, but at this point we’re barely learning to walk. We should focus on quantity rather than quality (only at this stage). Since things are still new to us, we gain much more by getting familiarized with the tools, rather than mastering them.</p><p>Focus on doing projects of around 100 lines of code. It could be more, it could be less. The size of the project doesn’t really matter. What matters most is that you start a project using what you’re learning, and finish it. You could work on a +1000 lines of code project if you want, but considering you’re learning something new, it’s highly unlikely you’ll finish it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jBq9YujyTrPqynPgI03wTA.gif" /></figure><p>The cool thing about focusing on quantity, is that with time, by nature you’ll start to focus on quality. For example, imagine you first focus on doing a calculator, then you focus on doing a simple game, and finally you focus on getting weather data. At the beginning, it might feel pointless. But with time, you’ll notice you already acquired skills to get data from an API, run a program, and create a GUI for it. UNTIL THEN you get to let your imagination run wild. Not while you’re still learning the basics.</p><h4>The framework</h4><ul><li>Define what features the end result will have. (Also see <a href="https://en.wikipedia.org/wiki/Minimum_viable_product">Minimum Viable Product</a>). Example:<br>Weather Analysis<br> — Today’s weather (pulled from an API)<br> — A DataFrame holding the weather for every state<br> — A bar chart showing the weather for every state<br> — A map visualizing the weather for every state<br> — An exported CSV of the data</li><li>If an important new feature is discovered during the process, add it to your plan and work on it.</li><li>After every feature is covered and working correctly, the project is marked as complete.</li></ul><h4>Where can I find projects though?</h4><p>Ask Google. Ask Chat GPT. Anything but procrastinating. You can search for “Beginner [whatever you’re learning] projects” or try to emulate something you like. Just be realistic. If you barely know what CSS means, don’t try to build a Twitter clone. Get your hands dirty, pick up some speed, and then give the big projects a shot.</p><blockquote>Search for projects on YouTube, Medium, books, or wherever you might find inspiration</blockquote><h4>Is cloning a project wrong?</h4><p>Not at first. If you’re learning, cloning a project will save you time on thinking about design, framework, etc. It’s even encouraged, since you can practice and prove your skills on an expected result. At this point, the priority is getting to work.</p><p>It becomes wrong when you’re already fluent on a new skill. At that point you’ll end up harming your creativity and restrain your imagination. When solving problems, you’ll always end up thinking in terms of the projects you emulated, instead of free thinking (you know other stuff is possible, you’re brave enough to try, etc.).</p><h3>But I’m comfy in my tutorial hell :(</h3><p>Well you shouldn’t be. We should treat engineering like we treat art. Art is very fun and fulfilling, but only when we have the ability to bring our vision to life. When we don’t have the capacity or ability, we learn about colors, shapes, etc. <strong>But the fun part is creating</strong>, not emulating.</p><p>At first it’s going to be a little uncomfortable, because no one will be grabbing your hand. But after a few small projects you’ll gain some confidence and feel the need to create something of your own.</p><p>As a suggestion, for every tutorial you watch (if it’s a good one), do 1-3 mini-projects. If it sounds too hard, try doing 1 guided project, 1 semi-guided project (doing it on your own, but with reference) and 1 unguided project.</p><blockquote>If we want to learn something new, we can’t escape tutorials. What we can do, is create a better relationship with them.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e5a93f6f07f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/how-to-escape-tutorial-hell-8e5a93f6f07f">How to Escape Tutorial Hell</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Types Unplugged]]></title>
            <link>https://medium.com/byte-sized-data/data-types-unplugged-80ef406ce204?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ef406ce204</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 18:53:56 GMT</pubDate>
            <atom:updated>2023-04-18T18:53:56.222Z</atom:updated>
            <content:encoded><![CDATA[<h4>From Numbers to Tags, Demystifying Data Categorization!</h4><figure><img alt="Data Types Cover" src="https://cdn-images-1.medium.com/max/1024/1*YXfBb3Uxr6oZvN_N1mykEA.png" /></figure><p>How useful can data be if we don’t even know how to categorize it? There are many ways to encode information, but there are some types that are better suited to communicate results (that’s most of a data professional’s purpose).</p><p>The most common types are <strong>numeric</strong> and <strong>categorical</strong>. Try to get these names tattooed or imprinted in your mind, since the concept alone tells a lot about what we are measuring.</p><h3>Numerical Data</h3><p>Its mostly numbers. The End. Well, not really. Numerical data can use additional symbols to identify units. Numerical data also breaks down in two main categories, <strong>continuous data</strong> and <strong>discrete data.</strong></p><h4>Discrete Data</h4><p>Discrete data focuses on whole numbers. Let’s say we’re counting people or cars. We turn into <a href="https://en.wikipedia.org/wiki/Count_von_Count">The Count from Sesame Street</a>: One Person, Two Person, Threeeee Person. But never 1.2 person or 2.5 person (<a href="https://www.imdb.com/title/tt0369179/">unless we’re talking about TV shows</a>). <em>Remember that the type of data being measured, reflects the reality of the thing being measured</em>.</p><figure><img alt="Vampire counting numbers" src="https://cdn-images-1.medium.com/max/1024/1*5PwbIFB8WxRM7dCPQ5XxOg.png" /></figure><h4>Continuous Data</h4><p>Continuous data focuses on the “in-betweens”. With discrete data we see things as entire objects, but what if we needed more precision?</p><p>Let’s imagine we work in The Olympics and we are the ones responsible for measuring javelin throws. I guess, <em>we could </em>use discrete data to measure the distance of the throws, but that would cause a lot of trouble. Athletes train their whole lives to gain extra centimeters in their throws, just for them to be erased by wrong measurements. If two athletes got 20.5m and 20.9m throws, with discrete data they would be treated as the same (either 20m or 21m, since the field wouldn’t be treated as a <strong><em>continuous line</em></strong>).</p><figure><img alt="Javelin thrower between measuring lines" src="https://cdn-images-1.medium.com/max/1024/1*ppfC99Cn7IR4EvrZX-sd8w.png" /></figure><h3>Categorical Data</h3><p>The way I see categorical data, is as if they were tags. It’s made up of words, symbols and even numbers, but they don’t behave in the same way. Categorical data is also broken down in two main types, <strong>ordinal data</strong> and <strong>nominal data</strong>.</p><h4>Ordinal Data (Ordered)</h4><p>When working with ordinal data, the order matters. Remember that categorical data can be seen as tags, but in this case, the order in which the tags are presented matters.</p><p>For example, shirt sizes are represented with categories (small, medium, large) in which the order represents a difference in size. The same applies with surveys in which you rank something from 1 to 10. In this case the categories are numbers, but they’re acting as tags, in which a 10 might represent “Very Good” and a 1 would be “Very Bad”.</p><figure><img alt="Different sized shirts" src="https://cdn-images-1.medium.com/max/1024/1*jrnPs5lBylsM2Q29KeKa4Q.png" /></figure><h4>Nominal Data (Unordered)</h4><p>Nominal data doesn’t care about an order. The categories or choices don’t follow a hierarchy. You can’t say that one option is better than the other or that an option is “greater than” another option.</p><p>For example, if a survey asks you a “Yes/No” question, the options provided aren’t really ordered in any way. If you’re choosing a color for your shirt, the order in which they’re presented doesn’t imply a hierarchy or importance.</p><figure><img alt="Shirts of different colors" src="https://cdn-images-1.medium.com/max/1024/1*ZJQMFAJfCoTQQRiEl2M-rw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ef406ce204" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/data-types-unplugged-80ef406ce204">Data Types Unplugged</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Project] Once Upon a Spark: Analyzing Shrek’s Script with PySpark]]></title>
            <link>https://medium.com/byte-sized-data/project-once-upon-a-spark-analyzing-shreks-script-with-pyspark-77fb73744dfd?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/77fb73744dfd</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 15:01:55 GMT</pubDate>
            <atom:updated>2023-04-07T15:01:55.561Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner level project to start using PySpark</h4><figure><img alt="Logo for the movie Shrek with Spark’s logo on top" src="https://cdn-images-1.medium.com/max/1024/1*D9xvC5ouqOX9HJS6tHHjdg.png" /></figure><p>Counting things is a great way to get started with Spark. Usually tutorials use books to count words as an introduction to start using Spark. In my case I felt it would be a little bit more fun using the script for the movie Shrek.</p><p>Let’s start mapping out this project before we begin. Doing an outline of our projects is always a good idea, specially when working with big data. For this project we will focus on 5 stages or steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kge2mRgTvMMELCibqzj-6A.png" /></figure><ul><li><strong>Reading</strong>: Read the script from a text file. To do this we might need to search for the script and create the file for ourselves.</li><li><strong>Tokenizing</strong>: Tokenize every word</li><li><strong>Cleaning</strong>: It’s more than likely that words might come with punctuation, character indications or things that aren’t words</li><li><strong>Counting</strong>: Count how many times a word occurs in the script</li><li><strong>Answering</strong>: Show which where the most common words (10, 50, 100)</li></ul><p>Before starting our process, let’s import the necessary libraries and create our Spark Session.</p><pre>import sys<br>from pyspark.sql import SparkSession<br>from pyspark.sql.functions import split, count, col, explode, lower, regexp_extract<br><br>spark = (SparkSession<br>  .builder<br>  .appName(&quot;ShrekWordCounter&quot;)<br>  .getOrCreate())</pre><h3>Reading</h3><p>Let’s get our data by loading the text file we filled with Shrek’s script. If you haven’t already, I suggest that before continuing, <a href="https://scienceleadership.org/blog/the_entire_shrek_movie_script">get the script from this website</a>. Now let’s load it into a DataFrame.</p><pre>shrek_script = (spark.read.format(&quot;text&quot;)<br>    .option(&quot;header&quot;, &quot;false&quot;)<br>    .option(&quot;inferSchema&quot;, &quot;true&quot;)<br>    .load(&quot;./shrek_script.txt&quot;)<br>    )</pre><h3>Tokenizing</h3><p>OK, reading the script wasn’t that hard right? Well tokenizing the whole script might be a little bit more complicated. First we should break down the script into lines.</p><pre>lines = shrek_script.select(split(col(&quot;value&quot;), &quot; &quot;).alias(&quot;line&quot;))<br>lines.show(10)</pre><blockquote>When creating my file, for some reason the script entered the text file as one giant string. If you had the same problem don’t worry, the code will work just the same.</blockquote><pre>+--------------------+<br>|                line|<br>+--------------------+<br>|[{Man}, Once, upo...|<br>+--------------------+</pre><p>Now the next logical step would be to break the lines into words. Giving an alias to the resulting column is a good practice, since the generating names might get confusing if you don’t keep track.</p><pre>words = lines.select(explode(col(&quot;line&quot;)).alias(&quot;word&quot;))<br>words.show(15)</pre><pre>+-----------+<br>|       word|<br>+-----------+<br>|      {Man}|<br>|       Once|<br>|       upon|<br>|          a|<br>|       time|<br>|      there|<br>|        was|<br>|          a|<br>|     lovely|<br>|  princess.|<br>|        But|<br>|        she|<br>|        had|<br>|         an|<br>|enchantment|<br>+-----------+</pre><h3>Cleaning</h3><p>Now that we have the whole script broken down into words, we need to make everything sort of standardized. To do that, let’s start by making everything lowercase.</p><pre>words_lower = words.select(lower(col(&quot;word&quot;)).alias(&quot;word_lower&quot;))<br>words_lower.show(15)</pre><pre>+-----------+<br>| word_lower|<br>+-----------+<br>|      {man}|<br>|       once|<br>|       upon|<br>|          a|<br>|       time|<br>|      there|<br>|        was|<br>|          a|<br>|     lovely|<br>|  princess.|<br>|        but|<br>|        she|<br>|        had|<br>|         an|<br>|enchantment|<br>+-----------+</pre><p>Great! Now to continue our cleaning process, we should get rid of symbols and words that aren’t really words. For example, the website where I got the script lays out the scene by writing things between curly braces. Even though they add context, for the analysis it’s just noise. To remove things, we’ll use the “regexp_extract” to get only words that match our regular expression. Our regular expression will focus on continuous strings of characters.</p><pre>words_clean = words_lower.select(<br>    regexp_extract(col(&quot;word_lower&quot;), &quot;[a-z]*&quot;, 0).alias(&quot;word&quot;)<br>)<br>words_clean.show(20)</pre><pre>+-----------+<br>|       word|<br>+-----------+<br>|           |<br>|       once|<br>|       upon|<br>|          a|<br>|       time|<br>|      there|<br>|        was|<br>|          a|<br>|     lovely|<br>|   princess|<br>|        but|<br>|        she|<br>|        had|<br>|         an|<br>|enchantment|<br>|       upon|<br>|        her|<br>|         of|<br>|          a|<br>|    fearful|<br>+-----------+</pre><p>Notice how words that didn’t match our regular expression got replaced by null values. We don’t want that either. To clean it up, we’ll filter our column using a “WHERE” clause just like in SQL.</p><pre>words_without_null = words_clean.where(col(&quot;word&quot;) != &quot;&quot;)<br>words_without_null.show()</pre><pre>+-----------+<br>|       word|<br>+-----------+<br>|       once|<br>|       upon|<br>|          a|<br>|       time|<br>|      there|<br>|        was|<br>|          a|<br>|     lovely|<br>|   princess|<br>|        but|<br>|        she|<br>|        had|<br>|         an|<br>|enchantment|<br>|       upon|<br>|        her|<br>|         of|<br>|          a|<br>|    fearful|<br>|       sort|<br>+-----------+<br>only showing top 20 rows</pre><p>Great! Now we have our data sparkly clean ;)</p><h3>Counting</h3><p>Now that we’ve gotten to the fun part, we first have to group all the words. Then after they’ve been grouped, we can count them.</p><pre>groups = words_without_null.groupBy(col(&quot;word&quot;))<br>results = groups.count()<br>results.orderBy(&quot;count&quot;, ascending=False).show(50)</pre><pre>+--------+-----+<br>|    word|count|<br>+--------+-----+<br>|       i|  406|<br>|     you|  406|<br>|     the|  230|<br>|       a|  225|<br>|      to|  168|<br>|      it|  160|<br>|    that|  135|<br>|      me|  134|<br>|     and|  120|<br>|      no|   90|<br>|      is|   87|<br>|      of|   87|<br>|      my|   86|<br>|     don|   77|<br>|    this|   77|<br>|    what|   76|<br>|      on|   75|<br>|      in|   73|<br>|    know|   70|<br>|      do|   63|<br>|     not|   62|<br>|    your|   61|<br>...<br>|      he|   31|<br>+--------+-----+<br>only showing top 50 rows</pre><p>It’s important to remember <a href="https://medium.com/byte-sized-data/the-lazy-spark-how-transformations-and-actions-work-together-442c7a4b0af1">how Spark handles actions and transformations</a>. In this particular case, <strong>groupBy()</strong> and <strong>count() </strong>are transformations, meaning that Spark will queue them lazily and nothing will happen until an action is called. If we didn’t add the <strong>show(50)</strong> action at the end, spark wouldn’t trigger the chain of computation. Btw, just so we have a little more clarity, this is how that chain would look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6gkjNJbO0KuthDAE8OvfZw.png" /><figcaption>Our data is scattered across 3 different partitions in our cluster</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LJpjHJo_GVEcGdod3OoCg.png" /><figcaption>Workers will perform individually the groupBy() and count() on every partition</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrWpYSYDN6O86WyVGilxxQ.png" /><figcaption>Finally every worker sends the summarized data to the master node</figcaption></figure><h3>Answering</h3><p>From what were able to observe, the most common words in the script were “I” and “You”. Awww, how cute, but not surprising. Any written content will require a myriad of pronouns and very common words. Even though we had these underwhelming revelations, we can still get some interesting insights. For example, if we see the top 50 most common words in the script, we can notice that Shrek (49 times) is mentioned more than Princess (39 times) or that swamp (20 times) is mentioned more than Fiona (17 times). At least we know Shrek’s priorities :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPYtiazLVn2SvhyBxyTkQw.png" /></figure><h3>Wrapping Things Up</h3><p>Just to finish our project with a gold star, let’s export it as a CSV. We don’t really have to, but it would be nice in case we need it in the future.</p><pre>results.coalesce(1).write.csv(&quot;./shrek_word_counts.csv&quot;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77fb73744dfd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/project-once-upon-a-spark-analyzing-shreks-script-with-pyspark-77fb73744dfd">[Project] Once Upon a Spark: Analyzing Shrek’s Script with PySpark</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data vs Information: What’s The Difference?]]></title>
            <link>https://medium.com/byte-sized-data/data-vs-information-whats-the-difference-4d2455f89ca2?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d2455f89ca2</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-literacy]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 16:02:13 GMT</pubDate>
            <atom:updated>2023-04-06T16:02:13.883Z</atom:updated>
            <content:encoded><![CDATA[<h4>Here’s why it matters more than you think</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOu9nF3h8OwTEeFQum_ZFg.png" /></figure><p>Since the dawn of internet people have been using data and information interchangeably. The world of data is becoming more and more relevant with the rise of AI, yet people still confuse these terms. The average person gets a pass, but data professionals shouldn’t.</p><p>Information is derived from knowledge. Knowledge is derived from activities (measurements, thoughts, debates, etc). This would imply that information is always being created. From neurons to sensors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-KH9hSW5OsseK5tbSoX5g.png" /></figure><p>The problem is that capturing information is not always so simple (much less communicating). The whole point is being able to communicate knowledge for the benefit of others or for storage. Because if we already know something, what’s the point of keeping to ourselves? One way of doing it is encoding our information. And that is data.</p><h3>Example</h3><p>There’s nothing better than a good ol’ example. In this case let’s imagine the story of a marketing company. Every month this company runs a different marketing campaign through various media (online, tv, magazines, etc). These campaigns generate information, thus creating data.</p><p>Tables with data are called datasets. Datasets have rows and columns that give us an understanding of the table. Rows are instances of associated information. In this example, each row would be a marketing campaign. Columns represent specific information. In this example we can compare each marketing campaign on specific information like profit or location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrO5qA3FqrJoKPgvslCxgw.png" /></figure><blockquote>Rows are also called observations, records, tuples or trials. Columns are also called features, fields, attributes, predictors or variables.</blockquote><p>As data professionals, we should familiarize ourselves with our workplace’s lingo. Different industries use different terms for the same concepts, and it’s important to know them so we can keep up in conversations.</p><p>Data points are intersections in tables. In this example, a data point could be that 100 units were sold on Halloween. It’s also important to mention that datasets have headers that indicate what each feature means, and paint the big picture. If headers are not included, it should be implied.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d2455f89ca2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/data-vs-information-whats-the-difference-4d2455f89ca2">Data vs Information: What’s The Difference?</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Project] Golden Ticket to Big Data: Exploring Wonka’s Candy Sales with Spark]]></title>
            <link>https://medium.com/byte-sized-data/project-golden-ticket-to-big-data-exploring-wonkas-candy-sales-with-spark-769c1575960b?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/769c1575960b</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 15:02:07 GMT</pubDate>
            <atom:updated>2023-04-06T15:02:07.983Z</atom:updated>
            <content:encoded><![CDATA[<h4>Join Willy Wonka’s team and learn how to use Spark to analyze candy sales data from around the world</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2r9QTr6qGQN0OBTy3nmHyw.png" /></figure><p>Imagine you opened your chocolate bar and found a golden ticket. What you didn’t know is that instead of winning a trip, you won an internship to work for Willy Wonka! Your first task is showing that you know how to handle Spark by creating an application of your choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JOiLSgtJFuGbWkhAiD-Pg.png" /></figure><p>To avoid doing the “Hello World!” of distributed computing (counting words), let’s try to be a little bit more creative. Let’s analyze some data about Wonka’s global candy sales. To make it stand out a little bit, let’s use data in the 100k range. We’ll do this only to enjoy Spark’s capabilities.</p><h3>Simulating Data</h3><p>Before we start anything, let’s import the necessary libraries and create an empty list to store our data.</p><pre>import pandas as pd<br>import numpy as np<br>data = []</pre><p>Let’s simulate the data by making a Python script that will create entries that represent how much candy sold in a country. To do this, first we should create a list containing the countries where Wonka sells his candy, and a list with the types of candy he sells.</p><pre>countries   = [&quot;USA&quot;, &quot;MEX&quot;, &quot;CAN&quot;, &quot;DEU&quot;, &quot;ITA&quot;, &quot;FRA&quot;, &quot;CHN&quot;, &quot;RUS&quot;, &quot;SAU&quot;, &quot;ARE&quot;, &quot;GBR&quot;, &quot;TUR&quot;, &quot;IND&quot;, &quot;BRA&quot;]<br>candy_types = [&quot;chocolate bar&quot;, &quot;white chocolate bar&quot;, &quot;dark chocolate bar&quot;, &quot;blueberry bubblegum&quot;, &quot;caramel popcorn&quot;, &quot;peanut butter pops&quot;, &quot;chocolate cookies&quot;, &quot;butter cookies&quot;, &quot;gummy bears&quot;, &quot;lollipops&quot;]</pre><p>Now let’s create a for-loop that runs 100k times or more (depends on how many you want). Then we will randomly create entries by matching a country, a candy and a random number between 100,000 and 10,000,000 simulating sales. Finally we’ll append the data as a dictionary.</p><pre>for i in range(100000):<br>  country = np.random.choice(countries)<br>  candy   = np.random.choice(candy_types)<br>  sales   = np.random.randint(100000, 10000000)<br><br>  data.append({&#39;country&#39;: country, &#39;candy&#39;: candy, &#39;sales&#39;: sales})</pre><p>Finally, let’s convert our data list to a Pandas DataFrame, and then save it as a CSV file.</p><pre>df = pd.DataFrame(data)<br>df.to_csv(&#39;candy_sales.csv&#39;, index=False) # We don&#39;t need to store the index</pre><p>Yay! Now we have some data to work with. Remember that if you want, you can change the amount of entries in our file and the sales amounts as well.</p><h3>Working With Our Data</h3><p>This is where the fun begins. As we did before, let’s start by importing the necessary libraries.</p><pre>import sys<br>from pyspark.sql import SparkSession<br>from pyspark.sql.functions import count</pre><p>To get the ball rolling, we should create a Spark session using it’s API. Remember that there can only be one SparkSession per JVM (JavaVirtualMachine), so in the rare case that it doesn’t exist, create an instance first.</p><pre>spark = (SparkSession<br>  .builder<br>  .appName(&quot;CandySalesCount&quot;)<br>  .getOrCreate())</pre><p>Now we need to get the filename for our candy sales report. This part depends on personal preference. We can “hard-code” it, or we can ask through the command-line. This is how both options would look like.</p><pre># Command-line option<br>candy_sales_file = sys.argv[1]<br><br># Hard-coded option<br>candy_sales_file = &quot;./candy_sales.csv&quot;</pre><p>Next we should load our file into a Spark DataFrame using a CSV format. To do that we should tell Spark to infer the schema and that our file contains a header. This way Spark automatically identifies the column names.</p><pre>candy_sales_df = (spark.read.format(&quot;csv&quot;)<br>  .option(&quot;header&quot;, &quot;true&quot;)<br>  .option(&quot;inferSchema&quot;, &quot;true&quot;)<br>  .load(candy_sales_file))</pre><p>For this exercise, we’ll be using the high level APIs instead of RDDs. This is because the exercise is so simple, we want to focus on telling Spark what to do, and not how to do it. Also, this will allow us to chain function calls, since these functions return the same object.</p><pre>count_candy_sales_df = (candy_sales_df<br>  .select(&quot;country&quot;, &quot;candy&quot;, &quot;sales&quot;)<br>  .groupBy(&quot;country&quot;, &quot;candy&quot;)<br>  .agg(count(&quot;sales&quot;).alias(&quot;Total&quot;))<br>  .orderBy(&quot;Total&quot;, ascending=False))</pre><p>Let’s see the resulting aggregations for each country and it’s sales. A total count of candy sales per state. Remember that <strong>show()</strong> is an action, so that means that it will trigger the query we just wrote and it will execute.</p><pre>count_candy_sales_df.show(n=60, truncate=False)<br>print(f&quot;Total Rows = {count_candy_sales_df.count()}&quot;)</pre><pre>+-------+-------------------+-----+<br>|country|candy              |Total|<br>+-------+-------------------+-----+<br>|ITA    |butter cookies     |779  |<br>|CAN    |white chocolate bar|769  |<br>|ARE    |blueberry bubblegum|767  |<br>|CAN    |lollipops          |762  |<br>|MEX    |caramel popcorn    |760  |<br>|IND    |butter cookies     |760  |<br>|RUS    |butter cookies     |757  |<br>|FRA    |white chocolate bar|756  |<br>|ARE    |gummy bears        |755  |<br>|TUR    |butter cookies     |753  |<br>|BRA    |gummy bears        |752  |<br>|ARE    |lollipops          |751  |<br>|ITA    |white chocolate bar|750  |<br>|TUR    |gummy bears        |750  |<br>|CHN    |butter cookies     |749  |<br>|RUS    |lollipops          |749  |<br>|TUR    |peanut butter pops |748  |<br>|CHN    |caramel popcorn    |748  |<br>|ITA    |lollipops          |745  |<br>|FRA    |gummy bears        |744  |<br>|CHN    |dark chocolate bar |742  |<br>|IND    |peanut butter pops |742  |<br>...<br>+-------+-------------------+-----+</pre><p>This gives us an overview of how many occurrences a candy was sold in each country. This doesn’t mean that 779 butter cookies were sold in Italy though, it means there were 779 sales occurrences (actual sales must be in the millions). If we wanted to dig a bit deeper, we can see the data for a specific country with the following code.</p><pre>ita_count_candy_sales_df = (candy_sales_df<br>  .select(&quot;country&quot;, &quot;candy&quot;, &quot;sales&quot;)<br>  .where(candy_sales_df.country == &quot;ITA&quot;)<br>  .groupBy(&quot;country&quot;, &quot;candy&quot;)<br>  .agg(count(&quot;sales&quot;).alias(&quot;Total&quot;))<br>  .orderBy(&quot;Total&quot;, ascending=False))<br><br>ita_count_candy_sales_df.show(n=10, truncate=False)</pre><pre>+-------+-------------------+-----+<br>|country|candy              |Total|<br>+-------+-------------------+-----+<br>|ITA    |butter cookies     |779  |<br>|ITA    |white chocolate bar|750  |<br>|ITA    |lollipops          |745  |<br>|ITA    |blueberry bubblegum|741  |<br>|ITA    |gummy bears        |723  |<br>|ITA    |chocolate cookies  |717  |<br>|ITA    |caramel popcorn    |702  |<br>|ITA    |dark chocolate bar |701  |<br>|ITA    |peanut butter pops |696  |<br>|ITA    |chocolate bar      |696  |<br>+-------+-------------------+-----+</pre><p>Remember to stop the spark session when you’re finished. As discussed in <a href="https://medium.com/byte-sized-data/distribute-conquer-a-playful-guide-to-sparks-distributed-execution-9608918db24b">a previous article</a>, each session holds resources like memory, CPU and connections to other services. Stopping the session will release all these resources. Not doing so will keep these resources inaccessible to other processes which might impact performance. In a shared environment this would be even worse, because you could impact other users who may need the same resources. So just as a good practice, always stop your Spark Session when you’re done using it.</p><pre>spark.stop()</pre><h3>What’s next?</h3><p>People at Wonka were impressed with your Spark skills. They said that they’ve been looking for someone with your capabilities.</p><p>If you want to get hired, consider doing the following:</p><ul><li>Get the total sales for each candy</li><li>Get the total sales for each candy by country</li><li>Get the total sales for each country</li></ul><blockquote>To solve these exercises, you might want to research a little bit into how to use other functions than count.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=769c1575960b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/project-golden-ticket-to-big-data-exploring-wonkas-candy-sales-with-spark-769c1575960b">[Project] Golden Ticket to Big Data: Exploring Wonka’s Candy Sales with Spark</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seeing is Believing: Spark’s Web UI]]></title>
            <link>https://medium.com/byte-sized-data/seeing-is-believing-sparks-web-ui-196fd1c57f5e?source=rss-a9058ad894b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/196fd1c57f5e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Beto Rendon]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 15:01:55 GMT</pubDate>
            <atom:updated>2023-04-05T15:01:55.837Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner’s guide to understanding Spark’s GUI</h4><figure><img alt="Spark logos in a browser icon" src="https://cdn-images-1.medium.com/max/1024/1*romHWA29X7mN8EumJPlPZw.png" /></figure><p>What? I didn’t know Spark had a GUI either. Apparently it does, so let’s get to know it better. As a brief introduction, the UI allows us to monitor stages for our Spark applications. This means that instead of imagining how operations break down, we can actually see it. We can see how Spark makes the decomposition of our jobs, stages and tasks.</p><p>Things might vary depending on the way we deploy Spark, but usually the driver will launch a web UI. This web UI will run by default on port 4040. The cool thing about this UI, is that we can see things like all the Spark SQL queries, a list of scheduler stages and tasks, memory usage, information about the executors, and some other stuff that might be interesting.</p><p>OK so let’s get started. First I made an empty text file and filled it with the lyrics for Eminem’s “My Name Is” song. I did that because I was kinda curious about how many times he says “Slim Shady” and because why not.</p><pre>[Chorus: Eminem]<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, what?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, what? (Excuse me) My name is, who?<br>My name is, chka-chka, Slim Shady<br>(Can I have the attention of the class for one second?)<br>Hi, my name is, huh? My name is, what?<br>My name is, chka-chka, Slim Shady<br><br>[Verse 1: Eminem &amp; Dr. Dre]<br>Hi, kids, do you like violence? (Yeah, yeah, yeah)<br>Wanna see me stick nine-inch nails through each one of my eyelids? (Uh-huh)<br>Wanna copy me and do exactly like I did? (Yeah, yeah)<br>Try &#39;cid and get fucked up worse than my life is? (Huh?)<br>My brain&#39;s dead weight, I&#39;m tryna get my head straight<br>But I can&#39;t figure out which Spice Girl I want to impregnate (Oh)<br>And Dr. Dre said, &quot;Slim Shady, you a basehead&quot; (Uh-uh)<br>&quot;Then why&#39;s your face red? Man, you wasted&quot;<br>Well, since age 12, I felt like I&#39;m someone else<br>&#39;Cause I hung my original self from the top bunk with a belt<br>Got pissed off and ripped Pamela Lee&#39;s tits off<br>And smacked her so hard I knocked her clothes backwards like Kris Kross<br>I smoke a fat pound of grass, and fall on my ass<br>Faster than a fat bitch who sat down too fast<br>Come here, slut; &quot;Shady, wait a minute, that&#39;s my girl, dawg&quot;<br>I don&#39;t give a fuck, God sent me to piss the world off<br><br>[Chorus: Eminem]<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, what?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, what?<br>My name is, chka-chka, Slim Shady<br><br>[Verse 2: Eminem]<br>My English teacher wanted to flunk me in junior high (Shh)<br>Thanks a lot, next semester I&#39;ll be 35<br>I smacked him in his face with an eraser, chased him with a stapler<br>And stapled his nuts to a stack of paper (Ow)<br>Walked in the strip club, had my jacket zipped up<br>Flashed the bartender, then stuck my dick in the tip cup<br>Extraterrestrial, running over pedestrians in a spaceship While they&#39;re screaming at me, &quot;Let&#39;s just be friends&quot;<br>99 percent of my life, I was lied to<br>I just found out my mom does more dope than I do (Damn)<br>I told her I&#39;d grow up to be a famous rapper<br>Make a record about doin&#39; drugs and name it after her<br>(Oh, thank you)<br>You know you blew up when the women rush your stands<br>And try to touch your hands like some screamin&#39; Usher fans<br>(Ahh, ahh, ahh)<br>This guy at White Castle asked for my autograph (Dude, can I get your autograph?)<br>So I signed it, &quot;Dear Dave, thanks for the support, asshole&quot;<br><br>[Chorus: Eminem]<br>Hi, my name is, huh? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br><br>[Verse 3: Eminem]<br>Stop the tape, this kid needs to be locked away (Get him)<br>Dr. Dre, don&#39;t just stand there, operate<br>I&#39;m not ready to leave, it&#39;s too scary to die (Fuck that)<br>I&#39;ll have to be carried inside the cemetery and buried alive<br>(Huh, yup)<br>Am I comin&#39; or goin&#39;? I can barely decide<br>I just drank a fifth of vodka, dare me to drive? (Go ahead)<br>All my life I was very deprived<br>I ain&#39;t had a woman in years and my palms are too hairy to hide (Whoops)<br>Clothes ripped like the Incredible Hulk<br>I spit when I talk, I&#39;ll fuck anything that walks (Come here)<br>When I was little, I used to get so hungry I would throw fits<br>How you gonna breastfeed me, Mom? You ain&#39;t got no tits<br>I lay awake and strap myself in the bed<br>With a bulletproof vest on and shoot myself in the head (Bang)<br>&#39;Cause I&#39;m steamin&#39; mad (Grr)<br>And by the way, when you see my dad (Yeah?)<br>Tell him that I slit his throat in this dream I had<br><br>[Chorus: Eminem]<br>Hi, my name is, what? My name is, who?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, what?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, who? My name is, huh?<br>My name is, chka-chka, Slim Shady<br>Hi, my name is, huh? My name is, who?<br>My name is, chka-chka, Slim Shady</pre><p>Then I ran pyspark in my console. I read the file I just created. Then I filtered it by the string “Slim Shady” to see how many times that string shows up in the text file. Then I just count it.</p><pre>&gt;&gt;&gt; song_lyrics = spark.read.text(&quot;./eminem-my_name_is.txt&quot;)<br>&gt;&gt;&gt; filtered = song_lyrics.filter(song_lyrics.value.contains(&quot;Slim Shady&quot;))<br>&gt;&gt;&gt; filtered.count()<br>17</pre><p>By going to localhost:4040 we can already see Spark’s UI. As an introductory exploration, let’s check out the DAG for the code we just executed. Lets first see the jobs so we can get a simple understanding of how it works.</p><figure><img alt="Spark UI showing DAG for a job" src="https://cdn-images-1.medium.com/max/1024/1*4H_N7BQ0HbfPug0luheJVg.png" /></figure><p>Now if we click on Stage 0, we should see how that stage went. The UI show’s us how the stage is composed and details about it. This will come in very handy later when we want to optimize our Spark code.</p><figure><img alt="Spark UI showing DAG for a stage" src="https://cdn-images-1.medium.com/max/1024/1*kiDXTJ2wjxghJL9xJsIZ2Q.png" /></figure><p>Concepts like “Exchange” or tasks being executed in parallel will become crucial, but for now the point was to become aware of Spark’s GUI and get to know it a little bit. I would recommend you try doing this exercise with something you’re interested in. Try not to deviate so much from the topic, but make it interesting.</p><figure><img alt="Spark in a browser" src="https://cdn-images-1.medium.com/max/1024/1*Zow5lpaIqTWS86j7sXCh2A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=196fd1c57f5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/byte-sized-data/seeing-is-believing-sparks-web-ui-196fd1c57f5e">Seeing is Believing: Spark’s Web UI</a> was originally published in <a href="https://medium.com/byte-sized-data">Byte-Sized Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>