<?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 Samuel Ayer on Medium]]></title>
        <description><![CDATA[Stories by Samuel Ayer on Medium]]></description>
        <link>https://medium.com/@ayersamuel07?source=rss-eae3a06310fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z3k0rvs9zocEzFo-CIYlFA.jpeg</url>
            <title>Stories by Samuel Ayer on Medium</title>
            <link>https://medium.com/@ayersamuel07?source=rss-eae3a06310fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:29:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayersamuel07/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[Accountability Partner]]></title>
            <link>https://medium.com/@ayersamuel07/accountability-partner-0d3d180189b9?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d3d180189b9</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[habits]]></category>
            <category><![CDATA[supabase]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 12:30:34 GMT</pubDate>
            <atom:updated>2025-08-01T13:45:25.183Z</atom:updated>
            <content:encoded><![CDATA[<h4>Building an Interactive Habit Tracker with Streamlit and Supabase</h4><p>⚡TL;DR:<br>I built Accountability Partner, a Streamlit-based habit tracking app with analytics dashboards powered by Supabase. <br>Over 20 users have used it to track more than 2,000 activities, with some reporting a 30% increase in productivity. <br>This article walks through how I built it, the challenges I faced, and what’s next.<br>🔗<a href="https://accountabilitypartner.streamlit.app/">Try the app</a> | 💻<a href="https://github.com/Outis09/AccountabilityPartner">View the code</a></p><h3>Table of Contents</h3><ul><li><a href="#6f0b">Introduction</a></li><li><a href="#27cd">Part I: Why Streamlit</a></li><li><a href="#d11d">Part II: An Analyst’s Approach to App Design</a></li><li><a href="#2af2">Part III: Analytics Dashboard — The Heart of the Project</a></li><li><a href="#3b5f">Part IV: Challenges and Lessons Learned</a></li><li><a href="#bdba">Part V: Future Plans</a></li><li><a href="#248e">Part VI: Conclusion</a></li></ul><h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pxm_e2zqCpOeSKrJ5M9Gbw.png" /><figcaption>App Logo, Generated with ChatGPT</figcaption></figure><p>If you’re anything like me, you probably have a growing list of activities you’re trying to juggle. I, for one, want to learn various data engineering tools, go to the gym, read daily, jog weekly, and journal.</p><p>Despite my best efforts, I often wondered: <em>How consistent have I actually been at each of these activities? How many days did I read in the past month? How much time have I truly invested in improving my Python skills?</em></p><p>These questions kept popping up anytime I reflected on my personal and professional growth, and that’s when my data analytics instincts kicked in. I needed to collect data on the activities I was engaging in so I could analyze them. To do this, I realized I needed a simple, personalized project where I could log these activities and analyze my progress over time.</p><p>Well, it started personalized, but it turned out my colleagues needed a similar tool, so I built it to support multiple users.</p><p>To bring the idea to life, I started with <a href="https://docs.python.org/3/library/tkinter.html"><em>Tkinter</em></a> for the desktop application and Streamlit for visualization, because I was already familiar with these tools. Later, I switched everything to a web app using <a href="https://streamlit.io/"><em>Streamlit</em></a>.</p><p>What started as a simple idea quickly evolved into a tool that has helped over 20 colleagues and friends track more than 2000 activities, with some reporting an increase in productivity of up to 30%. Interestingly, while I had designed the app expecting work-related habits to dominate, users logged wellness habits like walking and journaling even more consistently.</p><p>In this article, I will walk you through the journey of building the Accountability Partner, the analytics-driven web app for tracking habits.</p><h3>Part I: Why Streamlit</h3><p>The first version of Accountability Partner used Tkinter for habit management features, such as creating habits and logging activities, and Streamlit for analytics only. The Streamlit analytics feature was linked to Tkinter through a button click.</p><p>Even though the Tkinter version worked perfectly, I had trouble bundling the app into an executable package to share with others. This was mainly because Streamlit’s framework did not allow bundling into executable files.</p><p>This challenge prompted the need to build Accountability Partner on a different framework that allowed multiple users. I settled on Streamlit for these reasons.</p><ul><li>Streamlit is built for Python developers and supports rapid dashboard creation.</li><li>Streamlit supports charts, forms, and user input</li><li>Streamlit apps are deployable online on Streamlit Cloud</li><li>I had already used Streamlit to build the analytics component.</li></ul><p>For these reasons, I rebuilt Accountability Partner from a standalone desktop program to a more accessible web app.</p><h3>Part II: An Analyst’s Approach to App Design</h3><p>From the start, I approached this project not just as a builder but also as a data analyst. The main offering of the app was analytics; therefore, the data fields included in the habit creation and activity logging features needed to serve an analytical purpose. I also considered data validation to ensure data quality, data storage, and data protection for secure access and user privacy.</p><h4>Data Points</h4><p><strong>Habit Creation<br></strong>In the habit creation form, these were my initial data points.</p><ul><li><strong>Category</strong>: To group and compare habits across different life domains.</li><li><strong>Habit</strong> <strong>Name</strong>: To track performance on individual habits.</li><li><strong>Motivation</strong>/<strong>Notes</strong>: To support future sentiment analysis of why users choose certain habits.</li><li><strong>Frequency</strong>: To calculate consistency by comparing expected vs. actual logs.</li><li><strong>Start and End dates:</strong> To define habit tracking windows and analyze duration trends.</li></ul><p>After building the first version with these data points, I realized additional data points would unlock even more meaningful insights. I imagined myself as a user and asked myself: <em>What additional insights would I want to see, and what data points would give those insights?</em></p><p>From this analytics viewpoint, I got the idea to include a “Tracking Type” field to define how each habit could be monitored. Users could now select:</p><ul><li><strong>Yes/No </strong>(for habits that can be logged by indicating whether it was completed or not, eg, Journaling)</li><li><strong>Count </strong>(for habits that can be logged by the number of times it was done, eg, Glasses of water consumed)</li><li><strong>Minutes </strong>(for habits that can be logged by time spent, eg, Time spent studying Python)</li></ul><p>For the <em>Count </em>and <em>Minutes </em>types, I also included a <strong>target value, </strong>which would allow the app to compare actual log values against user-defined goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-4xMQnfHuFjUESNTxQE_w.png" /><figcaption>Main Habit Creation Window</figcaption></figure><p>Creating habits is just the beginning. To understand progress, users need a simple way to log their activities regularly</p><p><strong>Activity Logs<br></strong>Once users have created habits, they can log their activities through another window. To ensure clean and insightful records, I required:</p><ul><li>Category and Habit Selection</li><li>Log Date</li><li>Activity Value (based on tracking type: Count or Minutes)</li><li>Rating (to capture subjective focus, productivity, or satisfaction)</li><li>Optional Comment (used later for sentiment analysis)</li></ul><p>This structure enabled quantitative and qualitative data collection to generate comprehensive habit analytics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TruSDNCqUAj3GCHSHLyMyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ens8xdv7oL06Dx9wQEBrA.png" /><figcaption>Activity Log Window</figcaption></figure><p>For both habit creation and activity logs, a preview of the entered data is displayed to users for confirmation before saving.</p><p>Collecting the right data points is just the start. Ensuring the accuracy and consistency of those data points was equally important, so I implemented data validation.</p><h4>Data Validation</h4><p>As a data analyst, I understand the impact poor data quality has on insights. Therefore, as I developed the app and collected various data points, I reflected on how user data can be wrongly entered. Then I implemented data validation to avoid such situations by prompting the user about any data quality issues.</p><h4><strong>Data Storage</strong></h4><p>Once users confirmed their data, it was saved in a database. In the first version of the app, I used SQLite3 to create a database. While SQLite3 worked, it struggled with multi-user support and remote deployment. Since I wanted each user to have secure, cloud-based access to their data, I decided to migrate to Supabase.</p><p>Supabase’s free tier limits storage (500MB), RAM (500MB), and bandwidth (5GB). So I created a table called <em>authorized_emails </em>where I added emails that can sign up and use the app. The goal is to remove this limitation when I upgrade to the PRO plan on Supabase.</p><p>Aside from <em>authorized_emails, </em>I had three main tables in the database.</p><ul><li><strong>Users: </strong>for user authentication</li><li><strong>Habits: </strong>for storing habits</li><li><strong>Activity Logs: </strong>for activity logs</li></ul><p>The habits and activity logs tables were both connected to the users table using the user ID as a foreign key, and the activity logs table was connected to the habits table using the habit ID as a foreign key. Below is a snapshot of the data model showing the relationships between the tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ZjXJFg-BOsFhvaUQww7Vw.png" /><figcaption>ERD</figcaption></figure><h4>Data Protection</h4><p>With the database in place and relationships mapped out, it was time to do what I enjoy the most—turning raw data into meaningful insights.</p><h4>Part III: Analytics Dashboard — The Heart of the Project</h4><p>As a data analyst, I didn’t just want users to track habits; I wanted users to understand their habits too. The real value of logging data lies in what the data can reveal. That’s why the analytics dashboard is the core of the Accountability Partner app.</p><p>Once users log their habits consistently, I wanted to generate insights that would help them answer questions like:</p><ul><li><em>How consistent am I with each habit?</em></li><li><em>Which habits am I falling behind on?</em></li><li><em>Am I improving over time?</em></li><li><em>Where am I most focused and productive?</em></li></ul><p>With these questions in mind, I built the analytics dashboard to provide comprehensive insights on habits. I included both quantitative and qualitative insights to give the users a holistic view of their habits.</p><h4>Main Insights</h4><ul><li><strong>Completion rate: </strong>This calculates how many days the habit was completed vs expected based on frequency. For example, for daily habits, the expected log is the number of days between the start date and the current date. A high completion rate tells the user they’re doing well, while a low completion rate draws a user’s attention to the habits that they’re not doing so well.</li><li><strong>Target comparison: </strong>For habits with <em>Count </em>or <em>Minute </em>tracking types, the app compares the actual log values to the target values to show progress as a percentage toward goal achievement. This tells the user how frequently they have been meeting their set targets.</li><li><strong>Ratings: </strong>This aggregates the user’s self-rated focus or productivity per activity. It allows users to reflect not just on whether they showed up but also on how well they felt about the effort.</li><li><strong>Comment insights: </strong>For users who provide comments during activity logs, the app provides qualitative context in the form of a word cloud and sentiment analysis. The sentiment analysis and word cloud allow users to identify patterns in motivation, mood, productivity, and blockers based on their reflection after completing an activity.</li></ul><p>With these main insights, I built the dashboard to have 2 main pages. The first page provided a general overview of all habits for a user. This page allowed users to filter to a habit category to get insights into all habits under a category. The second page, which focuses on individual habits, allows users to drill down into each habit.</p><p>To demonstrate the analytics features to users who want to explore Accountability Partner’s main offerings, I created a demo section. This demo section displays the analytics dashboard exactly as users will see it, but with fake data.</p><p>Below is a GIF of the Overview page of the analytics dashboard taken from the Demo page.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQGb3YxM2ZXb2xqxcjQ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FQGb3YxM2ZXb2xqxcjQ&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYzdqcWplY2M4NHBuYzVpbWJ1Yzdyd25oaHI0d2Y1eG41bDlyZDZ4aiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FQGb3YxM2ZXb2xqxcjQ%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="218" frameborder="0" scrolling="no"><a href="https://medium.com/media/9750cdca45b950336ef264e3e543d407/href">https://medium.com/media/9750cdca45b950336ef264e3e543d407/href</a></iframe><p>Experience it live: <a href="https://accountabilitypartner.streamlit.app/">Accountability Partner Demo</a></p><p>Building out the analytics dashboard was a rewarding experience, but getting to that point came with its fair share of technical and conceptual challenges.</p><h4>Part IV: Challenges and Lessons Learned</h4><p>Developing Accountability Partner was not without challenges. When I started building Accountability Partner in Streamlit, my knowledge of Streamlit’s capabilities was very limited, so I ran into some challenges.</p><h4>Multi-user Management</h4><p>The major technical challenge I faced when I moved from Tkinter to Streamlit was how to handle multi-user data securely. I didn’t know how to set up the app to handle user log ins and signups. Through research, I discovered <a href="https://github.com/mkhorasani/Streamlit-Authenticator">Streamlit-Authenticator</a>, a Streamlit feature built to handle multi-user functionalities such as log in, sign up, forgot username, and forgot password. Streamlit-Authenticator uses a config.yaml file in which it dumps user log in and sign up information.</p><p>Streamlit-Authenticator worked locally, but when I deployed the app to Streamlit Cloud, I could not figure out how to keep the config.yaml file updated. This meant I had to build an authentication system of my own. Having already created two tables in Supabase for habits and activity logs, I created two more tables: preauthorized_users to hold emails of preauthorized users and users to hold user details after sign up. With these two tables, I combined Python functions and Streamlit’s session state functionality to build a custom authentication system for Accountability Partner.</p><h4>Going Beyond My Comfort Zone</h4><p>As a data analyst, I’m comfortable with writing SQL queries and visualizing data using Power BI, Excel, and Python. But building an app meant I had to think like a developer by managing user states, handling UI logic, and scalability.</p><p>It was a steep learning curve at first, especially figuring out how to structure the code so it remained modular and easy to update. However, I love challenges, so I took it on, and I actually enjoyed it.</p><h4>Part V: Future Plans</h4><p>While the current version of Accountability Partner already offers valuable habit tracking and personalized analytics, there’s still so much more I want to build. The long-term goal is to take Accountability Partner beyond being just a tracker into an actual accountability system, helping users set goals, stay consistent, and, most importantly, grow through actionable insights.</p><p>With this goal in mind, here’s what’s currently on the roadmap.</p><ul><li>An optimized mobile version to track habits on the go.</li><li>Habit reminders in the form of email prompts.</li><li>Use AI for habit trend detection and performance forecasting</li><li>Accountability circles where users can invite their trusted peers to view and support their progress.</li></ul><p>The roadmap is ambitious, but each new feature will be guided by one principle:</p><blockquote>Insights first. Always.</blockquote><p>Because understanding behaviour is the first step towards real change.</p><h4>Part VI: Conclusion</h4><p>What started as a personal project to track my habits has grown into a tool that’s helping others do the same, with structure, data, and intention.</p><p>Building Accountability Partner pushed me beyond my comfort zone because I had to think like a developer, a designer, and most importantly, a user. I learned that you do not need to have the perfect stack to get started. You just need a clear problem, a thoughtful approach, and the willingness to iterate.</p><p>For me, this wasn’t just about building an app. It was about leveraging data to create a system that made reflection measurable, consistency visible, and growth intentional.</p><p>🚀 Try the app:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Faccountabilitypartner.streamlit.app%2F%3Fembed%3Dtrue&amp;display_name=Streamlit&amp;url=https%3A%2F%2Faccountabilitypartner.streamlit.app&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fs4a-prod-share-preview%2Fdefault%2Fst_app_screenshot_image%2F98526896-8730-4213-a1c4-bd1102fbfaad%2FHome_Page.png&amp;type=text%2Fhtml&amp;schema=streamlit" width="560" height="630" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1c03787edbeb284b9817715b9b1032d/href">https://medium.com/media/b1c03787edbeb284b9817715b9b1032d/href</a></iframe><p>💻 View the code on <a href="https://github.com/Outis09/AccountabilityPartner">GitHub</a></p><p>If you’re interested in trying the app or collaborating on future features, I’d love to hear from you. Let’s connect on <a href="https://www.linkedin.com/in/samuel-ayer/">LinkedIn</a>.</p><p><a href="#93cc">Back to top.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d3d180189b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Assessment and Cleaning on Housing Market Dataset]]></title>
            <link>https://medium.com/@ayersamuel07/data-assessment-and-cleaning-on-housing-market-dataset-76788bfbd2a6?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/76788bfbd2a6</guid>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[numpy]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 09:31:22 GMT</pubDate>
            <atom:updated>2023-04-24T09:31:22.352Z</atom:updated>
            <content:encoded><![CDATA[<h4>Leveraging Python to assess and clean Melbourne Housing Market dataset</h4><h4>Introduction</h4><p>This article is an exemplary guide to data assessment and data cleaning in Python. This article assumes users have prior knowledge of Data Assessment and issues that make a dataset messy. If you are unfamiliar with these, read this article that talks about <a href="https://medium.com/@ayersamuel07/data-assessment-in-python-using-pandas-b47318f42aef">Data Assessment in Python</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cf6LI9ED2zgT6DHZbmhDbQ.jpeg" /></figure><p>The dataset used in this article can be downloaded from <a href="https://www.kaggle.com/datasets/dansbecker/melbourne-housing-snapshot">Kaggle</a>.</p><p>Let’s explore the features of the data before we dive in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*WkXu5oasDDAgRnT7FuKjSw.png" /><figcaption>Data description</figcaption></figure><p>Now that we are familiar with the columns in the dataset, let’s import the necessary libraries and import the data as well. To follow, run the code snippets in your Jupyter Notebook but you’d first have to <a href="https://www.kaggle.com/datasets/dansbecker/melbourne-housing-snapshot/download?datasetVersionNumber=5">download the data</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62ecd2a94afe2135250c51aa6123d65a/href">https://medium.com/media/62ecd2a94afe2135250c51aa6123d65a/href</a></iframe><p>After importing the libraries, let’s import the data and display the first five rows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71720d16e14aeee53cb3cb9e3800c857/href">https://medium.com/media/71720d16e14aeee53cb3cb9e3800c857/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*X2F7x_ax8n0zbxt5TpZwqg.png" /><figcaption>First five rows of data</figcaption></figure><p>Can you identify a few data issues from the rows displayed above?</p><p><strong>NB: </strong>A few columns are not displayed due to Jupyter Notebook’s limitations.</p><p>After importing the data, let’s proceed to data assessment.</p><h4>Data Assessment</h4><p>We’ll start by checking the shape of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*kBFTDDaUlKB9uGykaHK48g.png" /></figure><p>The dataset has 13580 rows and 21 columns. Let’s display some information on the columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*LVrGJcEjyQi1PXZPeNlUaA.png" /></figure><p>From the column information we can notice a few data issues.</p><ul><li>The datatype of YearBuilt , Bedroom2 , Bathroom, and Car should be int instead of float</li><li>Datatype of Date should be datetime</li><li>Postcode, Lattitude and Longtitude should be object because they do not have any numeric value</li><li>The column label Bedroom2 should be Bedroom</li><li>The column labels Lattitude and Longtitude are misspelt</li><li>SellerG and Car are not descriptive of the values in them</li><li>The column labelling is inconsistent</li><li>There are null values in the data</li></ul><p>Let’s check the summary statistics of the columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*WaCaDPup7MtwQaWW843mwA.png" /></figure><p>Some of the columns like Lattitude , Postcode and Longtitude that do not have any numeric value appear because of their datatypes.</p><p>Now let’s check the number of null values in each column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*X3eVQj0SoZ4TK7ucyJ44wQ.png" /></figure><p>Four columns have null values.</p><p>Let’s check if there are any duplicated rows in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*FYJTAmQSGAEBrVFaK18p5g.png" /></figure><p>There are no duplicate rows in the dataset.</p><p>After Data Assessment, these are the data issues identified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*ZKYMWiPOD0jqggqVVmhyUg.png" /></figure><p>Now that we have assessed the data, let’s proceed to clean the data.</p><h4>Data Cleaning</h4><p>As best practice, it is advisable to create a copy of the data before proceeding with data cleaning. So let’s create a copy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*PtctQmDa_B2YTQPeoT-HhA.png" /></figure><p>The data has successfully been copied. For the cleaning, we will use four steps. The four steps to be used in data cleaning are as follows.</p><ul><li>State the <strong>issue</strong></li><li><strong>Define</strong> the steps to be used in cleaning the issue</li><li>Write <strong>code</strong> to clean issue</li><li><strong>Test</strong> data to confirm cleaning was effective</li></ul><p>Now with these steps, we will start our Data Cleaning. We will start with the missing values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*eOGg8eAPP3lbrttgzhbljg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*WIN2JlxxsggM_RqsuOyZKw.png" /></figure><p>The Car column has 0.46% missing values. The YearBuilt and BuildingArea have approximately 40% and 48% missing values respectively. The CouncilArea column has 10% missing values.</p><p>Given the large percentage of missing values in the YearBuilt and BuildingArea columns, we will drop these columns from the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*3EdYYdcm8YrLVigyosyaYg.png" /></figure><p><strong>NB:</strong> If the YearBuilt and BuildingArea are relevant to your analysis, then you can impute them with the mean or median depending on the distribution of values. For demonstration, below is the code to impute a column with the mean.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2262508941faf612ec6ed7ea77462e0/href">https://medium.com/media/b2262508941faf612ec6ed7ea77462e0/href</a></iframe><p>For the CouncilArea column, we will replace null values with ‘undefined’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*zIERVE5ZfqlZ1kXkKrJlhQ.png" /></figure><p>The missing values in the Car column are small (0.46%), therefore we will drop those rows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*PqisVo9nvmcAEA2Pf0eQPw.png" /></figure><p>After using codes to handle the missing values, let’s test to see if the issue has been cleaned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*DQFiGlguJ1TqLpyu_GPcyA.png" /></figure><p>From the test, we can see that all missing values have been handled. Let’s proceed to the next issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*YiP4mVcGDk6ZlYsoZAXLLQ.png" /></figure><p>For this, let’s create a function to avoid repetitive codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*0r7KIVAz4whh_2jrpEeNTw.png" /></figure><p>Now, let’s use the function to change the datatypes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*NFqxr8yvfn1qS6frdhqLdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*dyTb0ZsgwGpUVGVXAsjuGA.png" /></figure><p>For the Date column we won’t use the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*4OPj-0vWI7T4NJ0d1L4CvQ.png" /></figure><p>After changing the datatypes, let’s confirm the change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*RkeJD2N-MfQYcpd-mAWGqw.png" /></figure><p>The datatype issue has been cleaned. Now let’s proceed with the column labelling issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*qKv5mJ5nemwIW0X-BaGvpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*MyYX2yKaUZPNougkKrAGXg.png" /></figure><p>After renaming the columns, let’s confirm the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*GzA9sohyqkikebF_dHVWGg.png" /></figure><p>Now we have successfully cleaned the dataset and can proceed to analysis. Some analysis ideas? What factors drive price? What factors affect a property’s chances of being sold?</p><p><strong>NB: </strong>There may be other issues in the values in some columns but cleaning them will depend on their relevance to your analysis. Check out the unique values in the AgentName column, do you see any data issues? Is it relevant to your analysis? If yes, can you clean it?</p><p>Check out this <a href="https://github.com/Outis09/Property-Pricing-Analysis">GitHub repository</a> that contains a Jupyter Notebook that analyzed the drivers of property pricing.</p><p>If you find this article insightful, don’t forget to clap and leave a comment.</p><p>Follow me on <a href="https://github.com/Outis09">GitHub</a> or connect on <a href="https://www.linkedin.com/in/samuel-t-ayer-3a278b221/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76788bfbd2a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revenue Analysis of Edu-Tech Firm]]></title>
            <link>https://medium.com/@ayersamuel07/revenue-analysis-6117f21afc99?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/6117f21afc99</guid>
            <category><![CDATA[revenue]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Fri, 31 Mar 2023 11:01:48 GMT</pubDate>
            <atom:updated>2023-05-08T11:39:54.094Z</atom:updated>
            <content:encoded><![CDATA[<h4>Leveraging MS Excel and Power BI to analyze revenue and make recommendations to increase revenue</h4><h4>Introduction</h4><p>In this project, I analyzed the data of Educative, an edu-tech firm, to track the performance of courses and to make recommendations on how revenue can be increased in the next quarter. I used Excel for data collection and consolidation, data cleaning and exploratory data analysis. Then I moved the data to Power BI where I performed more detailed data analysis and visualization. I was able to derive insights and make recommendations.</p><p>This project was undertaken as a capstone project for my data analytics fellowship with <a href="https://blossom.africa/">Blossom Academy</a>.</p><h4>Table of Contents</h4><ul><li><a href="#cd00">Business Problem</a></li><li><a href="#a15b">Data Collection</a></li><li><a href="#c5ba">Data Assessment and Cleaning</a></li><li><a href="#b117">Data Analysis</a></li><li><a href="#1ccc">Data Visualization</a></li><li><a href="#a449">Insights and Recommendations</a></li><li><a href="#0bc6">Conclusion</a></li></ul><h4>Business Problem</h4><p>The firm, Educative, is seeking opportunities to increase revenue for the next quarter. As the data analyst, I have been provided with data on courses from different topics and I am expected to analyze course revenue from this data and make recommendations on how to increase revenue. The current suggestion is to increase the price of the best performing subjects. I am therefore also to analyze the data to see if the suggestion is backed by data.</p><h4>Data Collection</h4><p>The data was stored in separate CSV files for each subject in <em>Educative</em>’s catalogue. I inspected each CSV file and noticed that the column names were the same across all the files. I decided to consolidate the data by appending all the files. To do this, I stored the data in one folder. I opened a new Excel workbook and selected the Data tab on the ribbon. From there, I selected New Query and selected folder as the data source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*sK-ZbtaBJLPegiFqFTZHjg.png" /><figcaption>Display window from New Query on the Data tab</figcaption></figure><p>I navigated to the folder containing the CSV files. In the preview window, I selected the option to <strong>Combine &amp; Load</strong> the data. The data was now consolidated into one Excel workbook. Below is a snapshot of the data after consolidation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxujbXsxRzUs2pewJ5faDw.png" /><figcaption>Consolidated data</figcaption></figure><p>I proceeded to assess the data to identify any data quality issues.</p><h4>Data Assessment and Cleaning</h4><p>I first checked the number of rows and columns in the data. There were 13 columns and 3677 rows.</p><p>Then I checked for null values in the data set. I displayed the unique values in each column to see if there were any blanks. In the course_id column, I noticed there were blank values so I filtered to display only the rows with blank values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQNzqh-J8dBjLMJqJQsrzQ.png" /><figcaption>Blank rows</figcaption></figure><p>I detected that the same rows had blanks in the other columns as well. I deleted these rows from the data.</p><p>Next, I decided to remove duplicates if there were any. Using Ctrl + A, I selected the entire data and selected the <strong>Table Design </strong>tab. From there I selected <strong>Remove Duplicates.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fOBxRPdL1wd1O4l5gUwDBg.png" /><figcaption>Remove Duplicates command</figcaption></figure><p>In the resulting window, I selected the option to check for duplicates in all columns. After running, there was a pop-up window indicating that there were no duplicate values in the data. I proceeded to manually inspect the data in the columns to identify any remaining issues in the data.</p><p>In the subject column, I realized that one of the subject’s title was different from the rest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*h9ut51vznoOO5FxkQaxEEw.png" /><figcaption>Column filtering window</figcaption></figure><p>I decided to make that subject title consistent with the others. I used the <strong>Ctrl + F</strong> shortcut to access the <strong>Find and Replace</strong> window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TEUlqnsNW9a9STRsHHYfNw.png" /><figcaption>Find and Replace window</figcaption></figure><p>The change was effected.</p><p>After inspecting the data in the columns, I decided to delete two columns because they would not be relevant to my analysis. These columns were Source.Name which contained the name of the CSV file the data was coming from, and url which contained the url of each course in the data.</p><p>Below is a snapshot of the data after data cleaning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JE0GKQMIwEVma0274hqhfQ.png" /><figcaption>Data after data cleaning process</figcaption></figure><p>Next, I proceeded to undertake a series of tasks that came with the data.</p><h4>Task 1</h4><p>The first task was to create a published_date column by extracting the date from the published_timestamp column.</p><p>For this task, I decided to use the INT()function to extract integers representing the date from the published_timestamp column. This is because dates are stored as numbers in Excel. The function returns a set of numbers. I then converted the data type of the column to short date. Below is the full function I used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ff09wi48kkV_HL02i5TVNg.png" /><figcaption>INT() function to extract year</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*LpH-W83d-uUiSrkODSwyWQ.png" /><figcaption>Results of INT() function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*Ej0-V_2Ory6CvMuwQC8AvQ.png" /><figcaption>Integers converted to short dates</figcaption></figure><h4>Task 2</h4><p>The second task was to create a column labeled free_or_paid indicating whether a course is Free or Paid.</p><p>In the price column, courses that were free had a price of zero. Therefore, I used an IF() function to solve the task. If the value in the price column was 0 then the course was free else the course was paid.</p><p>I inserted a new column and named it free_or_paid then I ran the IF() function in this new column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQwX7tIhFH0jLKgqenPHtg.png" /><figcaption>IF() function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*xutSgC_zj1Ru2eY8At6cWw.png" /><figcaption>Results of IF() function</figcaption></figure><h4>Task 3</h4><p>The third task involved displaying some features of the top 20 most subscribed courses on a separate sheet. The features included:</p><p>● Their level</p><p>● Whether they are free or paid</p><p>● Duration of the course</p><p>● The date they were published</p><p>To do this, I first arranged the data in descending order of number of subscribers. Then I copied the course IDs to a different worksheet. I used the <strong>VLOOKUP() </strong>function to retrieve the needed columns. I then applied formatting and labelled the columns. I named the worksheet ‘Top 20 Courses’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*qdGx-UgCvBmFqoc_H0DyqQ.png" /><figcaption>VLOOKUP() function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*pC8CnmAW_cLxoEddjgMrqw.png" /><figcaption>Results of VLOOKUP() function</figcaption></figure><h4>Data Analysis</h4><p>I used pivot tables and charts to conduct exploratory data analysis. I started the exploration by looking at the number of courses for each subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*Q9PtUfpPCI6EEUg2blksVA.png" /><figcaption>Pivot table</figcaption></figure><p>Then I checked the number of courses that were paid and those that were free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*Vm93OEJiLd4EfLBUCRAvWQ.png" /><figcaption>Pivot table</figcaption></figure><p>I checked the number of courses by each course level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*Gaw9KjvmeNWvAX-juoSRWA.png" /><figcaption>Pivot table</figcaption></figure><p>I also inspected the revenue by each subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*Ji27ijD_uYlhcTyS-M69yA.png" /><figcaption>Pivot table</figcaption></figure><p>After revenue by subject, I explored the revenue by course level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*GXfl2SxTRJDP0CkDnwypYg.png" /><figcaption>Pivot table</figcaption></figure><p>I also explored the revenue over the years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*23ZuIsaFuHQg1T0FHroSrA.png" /><figcaption>Pivot Table</figcaption></figure><p>After exploring revenue by subject, course level and year, I proceeded to explore the average course price. I first inspected the average course price by subject. Since only the aid courses I filtered for only paid courses so that free courses will not affect the average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*vrclBO-SYQoZCiLg5EJSjA.png" /><figcaption>Pivot table</figcaption></figure><p>I broke this down further by looking at the average course price per course level per subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*lPvXlAhUrtK-UOrFpbxfrQ.png" /><figcaption>Pivot table</figcaption></figure><p>Finally, I looked at the average course price over the years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*u1Pw1aSoqkuC6dMVyICpww.png" /><figcaption>Pivot table</figcaption></figure><p>I exported the data to Power BI for more detailed data analysis and visualization.</p><h4>Power BI</h4><p>As a standard procedure, when I am working with data that has dates, I use Data Analysis Expressions(DAX) in Power BI to create a date table. This makes it easier to work with date functions compared to the original date columns which may have some missing dates. In this data, the date column, published_date , had missing dates therefore the date table was necessary. I created a table of date starting from 1st January 2011 to 31st December 2017. Below is the DAX function I used to create the date table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KF-vuwuCVSiGyKdAgx-2TQ.png" /><figcaption>DAX for date table</figcaption></figure><p>After creating the date table, I had to establish a relationship with the existing table. Using Power BI’s data modelling, I connected the two tables using the date columns. Below is the data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*5Pdd-kv1-8YvG55FMSWxhA.png" /><figcaption>Data Model</figcaption></figure><p>I created various measures to aid my analysis. With measures too, I prefer to create a measures table to contain all measures. So I created a measures table then proceeded to write measures to be stored in the table.</p><p>Like I did in Excel, I created a measure to calculate revenue because the business problem centered around revenue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*b8iPzoLx-vZmY18-yv_Ilg.png" /><figcaption>DAX for revenue</figcaption></figure><p>To understand <em>Educative</em>’s revenue, I needed to analyze the premium subscribers and number of paid courses. I created DAX measures to get this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*IX93aryFyMrqTJROuz33_Q.png" /><figcaption>DAX for Premium Subscribers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*37xdy6Jtu1ZNGjyG9LVK6Q.png" /><figcaption>DAX for paid courses</figcaption></figure><p>The current year in the data is 2017 and the last date was the 6th of July. To understand the revenue so far in the year, I decided to analyze the revenue of the year to date compared with the same period the previous year, which is 2016. To do this, I had to create measures to get the revenue, premium subscribers, average price of a course, paid courses for the year to date and the same period last year. Below are snapshots of some of the DAX measures I used to achieve this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*bdYr2bS7mU6FJBZBVA409w.png" /><figcaption>DAX for Total Revenue YTD</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*sqXXgMbErNbcHFiNFY6cmQ.png" /><figcaption>DAX for Total Revenue Previous Year</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*YvHLNJT09ps0MHH-oslE3Q.png" /><figcaption>DAX for Paid Courses YTD</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*aynRque-QgHjEt5Ikymy-w.png" /><figcaption>DAX for Paid Courses Previous Year</figcaption></figure><p>Below is a snapshot of the data model after I created the measures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*8tASvrLxt1FYl7AYDzm6tw.png" /><figcaption>Data Model</figcaption></figure><p>For my analysis in Power BI, I focused on only the paid courses because the aim was to increase revenue. I analyzed the data with charts in Power BI. I created three report pages detailing my insights and basis for my recommendations.</p><h4>Data Visualization</h4><p><strong>Year to date Analysis<br></strong>On the first report pages, I focused on the current year which in this case was 2017. I analyzed the performance so far and compared it to the same period the previous year. The key performance indicators I added to the report include:</p><ul><li>Total revenue year to date</li><li>Premium subscribers</li><li>Average course price year to date</li><li>Number of paid courses</li><li>Average course duration</li></ul><p>I added the option to filter by subject and course level. Below is the report page for this analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7vrgs-_03OBgElHSaxGzA.png" /><figcaption>Year-to-Date report</figcaption></figure><p><strong>Subject Analysis<br></strong>On the second report page, I proceed to analyze the best performing subjects historically. The source of revenue is the paid courses Educative is offering so I wanted to check which subject is responsible for the most revenue over the period. Aside revenue, I checked the number of premium subscribers, number of paid courses and the average course price for each subject. Below is the report page for the analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYF06t-BenMnONZmbjaLgA.png" /><figcaption>Subject report</figcaption></figure><p><strong>Course Level Analysis<br></strong>After analyzing the best performing subjects, I analyzed the best performing course levels. The four course levels in Educative’s catalogue are:</p><ul><li>Beginner</li><li>Intermediate</li><li>Expert</li><li>All Levels</li></ul><p>I analyzed the revenue, premium subscribers, paid courses and average course price by the course levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndx81BvpG3P8kVIBal0fwQ.png" /><figcaption>Course Level report</figcaption></figure><p>Interact with the <a href="https://app.powerbi.com/view?r=eyJrIjoiZGZlYWYxYTYtZTJmYS00NDg0LWIzMjgtNTc3MDNiYzVjM2FhIiwidCI6IjFmMmEyODZiLWViYzctNGJmZC1hYjE0LWE3YTlhNmJhMTk5MyJ9">Power BI report here</a>.</p><h4>Insights and Recommendations</h4><p><strong>Insights<br></strong>📌 <strong>Total revenue</strong> has <strong>reduced</strong> by <strong>42%</strong> compared to the same period last year</p><p>📌<strong>Revenue</strong> from <strong>Musical Instruments</strong> courses has <strong>risen</strong> by <strong>95%</strong> compared to the previous year.</p><p>📌 <strong>Number of premium subscribers</strong> has <strong>reduced</strong> by <strong>40%</strong> compared to the same period last year.</p><p>📌 The average cost of a paid course has increased by <strong>12%</strong> and the number of paid courses has <strong>increased</strong> by <strong>6%</strong> compared to the same period last year.</p><p>📌 Web Development accounts for <strong>68%</strong> of the premium subscribers. It is the most popular subject in our subject catalogue.</p><p>📌 With a total revenue of <strong>$631M</strong>, Web Development accounts for <strong>71%</strong> of the total revenue of Educative.</p><p>📌 On the average, Web Development courses cost more than courses from the other subjects in our catalogue.</p><p>📌 Courses designed for <strong>all levels</strong> account for<strong> 52%</strong> of premium subscribers followed by courses designed for<strong> beginners</strong> which accounts for <strong>37%</strong> of our premium subscribers.</p><p><strong>Recommendations<br></strong>🎯 Publish more Web Development and Musical Instruments courses for All Levels and Beginners</p><p>🎯 Conduct market research to compare course prices to that of competitors. Review course prices if prices are higher than our competitors</p><p>🎯 Increase content duration for newly published courses to an average of 4.4 hours</p><h4>Conclusion</h4><p>The suggestion that the prices of the best performing courses should be increased is not data driven. This is because the data shows that in the current year, revenue and premium subscribers have decreased substantially even though the prices of courses has increased. Therefore, increasing the prices may course a further decline in revenue and premium subscribers.</p><p>A more data driven line of action is to publish more Web Development and Musical Instruments courses for all levels and beginners. It is also advisable to review the prices of courses by comparing with the price of similar courses on the market. Furthermore, the average content duration should be increased to the previous year’s average of 4.4 hours.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6117f21afc99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Employee Attrition Analysis]]></title>
            <link>https://medium.com/@ayersamuel07/employee-attrition-analysis-8f96a8d8126?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f96a8d8126</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[business-analytics]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[attrition]]></category>
            <category><![CDATA[microsoft-excel]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 07:37:05 GMT</pubDate>
            <atom:updated>2023-02-20T07:37:05.417Z</atom:updated>
            <content:encoded><![CDATA[<h4>Analysis of employee attrition with Microsoft Excel and Power BI. Extracting insights from data and making recommendations based on insights.</h4><p>In this project, I combined MS Excel and Power BI to understand why employees in an organization were leaving.</p><h4>Table of Contents</h4><ul><li><a href="#4175">Data gathering</a></li><li><a href="#5a1b">Business questions</a></li><li><a href="#341d">Data cleaning</a></li><li><a href="#4e5c">Exploratory data analysis</a></li><li><a href="#4860">Reports and Visualizations</a></li><li><a href="#1e53">Insights and Recommendations</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*mCPiYDB_TXgLiS1-C3K0Vw.jpeg" /></figure><h4>Data Gathering</h4><p>The data used in this project was downloaded from <a href="https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset">Kaggle</a>. It contains 35 columns and 1470 rows. The dependent variable in the data was the ‘<em>Attrition</em>’ column. It contained ‘<em>Yes</em>’ for employees who had left the organization and ‘<em>No</em>’ for employees who were still at the organization. The independent variables can be broken into the following categories.</p><p><strong>Basic info:</strong></p><p>Age, Gender, Over 18, Education, Education Field, Marital Status, and Distance from home</p><p><strong>Work info:</strong></p><p>Employee count, Employee number, Department, Job role, Job Level, Overtime, Business travel, Performance rating, Standard hours, Stock option level and Job involvement</p><p><strong>Satisfaction:</strong></p><p>Work-life balance, Job satisfaction, Relationship satisfaction, Environment satisfaction</p><p><strong>Salary Related:</strong></p><p>Monthly income, Monthly rate, Daily rate, Hourly rate, Percent salary hike</p><p><strong>Time Related:</strong></p><p>Total working years, Training times last year, Years at company, Years in current role, Years since last promotion, Years with current manager, Number of companies worked at.</p><h4><strong>Business Questions:</strong></h4><p>Before I started exploring and analyzing the data, I asked some business questions I intended to answer from the data. I assumed I was analyzing for an HR manager and as such, these questions were from the HR manager who wanted to understand why employees were leaving the organization.</p><ul><li>What is the attrition rate?</li><li>Which department and job role has the highest attrition rates?</li><li>What factors contribute to attrition?</li><li>Which demographic of employees are more likely to leave the organization? Should this affect our hiring policy?</li><li>What can be done to reduce attrition?</li></ul><h4><strong>Data Cleaning:</strong></h4><p>I imported the data into MS Excel, converted the data into a table, and named the table ‘<em>_attrition_data</em>’. I first checked for any empty cells using the COUNTBLANK() function. The function returned 0 indicating that there were no empty cells in the table.</p><p>I then checked for duplicates using the <em>Highlight Cell Rules</em> option under <em>Conditional Formatting</em> on the <em>Home ribbon</em>. I formatted for duplicate values to be highlighted in red. I checked the data and realized no rows had been highlighted in red so there were no duplicates in the data.</p><p>I proceeded to assess the individual columns to identify any data issues.</p><p><strong>Actions:</strong></p><ul><li>Added km to <em>DistanceFromHome</em> column to indicate the measurement.</li><li>The following columns had numbers representing the actual levels so I replaced the numbers with the actual levels.<br>- Education<br>- Environment satisfaction<br>- Job involvement<br>- Relationship satisfaction</li><li>I deleted the following columns because the values in each row were the same.<br>- Employee count<br>- Over18<br>- Standard hours</li></ul><h4><strong>Exploratory Data Analysis:</strong></h4><p>I opened another Excel workbook and imported the cleaned data using Power Pivot. I created a measure named “Number of Employees” to get the total number of employees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*DaCkquuoFJ_ja73L8ddQkw.png" /><figcaption>Measure for total number of employees</figcaption></figure><p>I created another measure named “Employee Attrition Count” to get the number of employees the company had lost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*HgEOZ_8ubucvfeuGvXKXhQ.png" /><figcaption>Measure for employee attrition count</figcaption></figure><p>The last measure I created was “Attrition Rate” which calculated the attrition rate using the first two measures I created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*Inb5GbZjmSm5WY-DqhKQ2A.png" /><figcaption>Measure for attrition rate</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ieavys63A1KR_wrZq0uDww.png" /><figcaption>Metrics</figcaption></figure><p>Now I proceeded to explore how the attrition rate was affected by the independent variables.</p><p>I used Pivot Table from Power Pivot for this.</p><p>I first wanted to investigate the number of employees and attrition rate for each department. In the pivot table, I put the department column into “Rows” and the 3 measures into “Values”. I sorted the values from largest to smallest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*DRxr7CYTtmr17DNGcAh_5g.png" /><figcaption>Breakdown by department</figcaption></figure><p>I wanted a breakdown of attrition by job role in each department so I added the <em>JobRole</em> column to Rows in the PivotTable Fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*xo2NvKG6NHhv-EzE0fgMIQ.png" /><figcaption>Breakdown by department and job role</figcaption></figure><p>Next, I looked at attrition rate by frequency of business travels. There were 3 different frequencies. That is, employees who never travelled, employees who rarely traveled and employees who travelled frequently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*YBaVx9izDokQ-10jGz7IEw.png" /><figcaption>Breakdown by business travel frequency</figcaption></figure><p>I compared attrition rate for the various education levels. Attrition rate for all education levels was above <strong>10%</strong>. Attrition rate was highest for employees whose educational qualifications were below college level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*PsOU9NmkBz5f56_1AQ5Pjw.png" /><figcaption>Breakdown by educational qualification</figcaption></figure><p>I then looked at attrition rate by overtime requirement. I wanted to find out if employees on overtime were more likely to leave to the organization. I discovered that attrition rate for employees on overtime was almost three times the attrition rate of those who were not on over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*3tVdMd_PTflrgE2X9MFeiA.png" /><figcaption>Attrition rate by overtime requirement</figcaption></figure><p>Since there are lots of independent variables in the dataset, I will just show a few other pivot tables for some of the independent variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*brnrkHhTV6veoi2ZhIJ_1g.png" /><figcaption>Breakdown by job involvement</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*RTfKHExAIJP7Dyj5xsRCEg.png" /><figcaption>Breakdown by job satisfaction</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*k5hf1Qw2g5kiLmb_w1Pn-Q.png" /><figcaption>Breakdown by gender</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*Bb2_2EpawodLl2GQ4Z_Lug.png" /><figcaption>Breakdown by marital status</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*w3ZV2IOV7IfrnKmQrg5pRg.png" /><figcaption>Breakdown by job level</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*TXhV0lV-xFnDOrQUV6bykw.png" /><figcaption>Breakdown by number of companies worked at</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*3Ph27DzlBNPjpGgn3gmWyA.png" /><figcaption>Breakdown by work-life balance</figcaption></figure><h4><strong>Visualization and Reports:</strong></h4><p>I imported the data into Power BI. I used Data Analysis Expressions(DAX) to replicate the 3 measures I created in Excel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*WF5umIHFfQw2brVdcK-m4w.png" /><figcaption>Measure for number of employees</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*1qCtYZjXSzy4T4yXbVoudQ.png" /><figcaption>Measure for attrition count</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*m8fgIIFuQ2vKfDCOr3hRYw.png" /><figcaption>Measure for attrition rate</figcaption></figure><p>I visualized the insights from Excel and arranged the visuals onto a multi-page report. The report had four pages.</p><h4><strong>Attrition Overview</strong></h4><p>This page contains the number of employees, a count of employees who had left the organization and attrition rate on visual cards. it contains a pie chart showing the department contributing the most to attrition. It breaks down attrition rate by job roles, job involvement level and overtime requirement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zoApaPbtakbI_oiMj0hi6A.png" /><figcaption>Overview</figcaption></figure><p><strong>Demographics and Attrition</strong></p><p>This report page focused on visualizing the demographic of employees who have left or are more likely to leave the organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcW1s6jbtWxy01YVV0PCtw.png" /><figcaption>Demographics and attrition</figcaption></figure><p><strong>Other Contributing Factors</strong></p><p>This page looks at other factors that contribute to attrition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*incPDdhIrSLqCnQPGqytpg.png" /><figcaption>Other contributing factors</figcaption></figure><p><strong>Attrition Risk Tracker</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-3Gq8hbI8Ug55RTY040TQ.png" /><figcaption>Attrition risk tracker</figcaption></figure><p>I created this tracker in Power BI to help the HR manager tracker the employees who were at risk of leaving. I used 10% as the threshold. When the number of employees belonging to a category with high attrition rates are more than 10% the number of active employees, the visual is displayed with a red font. It is displayed with green font otherwise. This tracker can be filtered by department therefore it allows the HR manager track the metrics for the entire organization and then for each department in the organization.</p><p><strong>NB:</strong> The reports are interactive and can be filtered to get a breakdown by category. To interact with the report, <a href="https://app.powerbi.com/view?r=eyJrIjoiOTJiYjdmZjgtOTA3ZC00YTAwLTk0ZDUtMmZiYzkwYjJmYjY2IiwidCI6IjFmMmEyODZiLWViYzctNGJmZC1hYjE0LWE3YTlhNmJhMTk5MyJ9">click here</a>.</p><h4><strong>Insights</strong></h4><ul><li>Attrition rate for the organization is at 16%.</li><li>The Sales department has the highest attrition rate compared to other departments.</li><li>Attrition rates for Sales Representatives is highest compared to other job roles.</li><li>Monthly income, over time, frequent business travels, job involvement, work-life balance and job satisfaction are the biggest drivers of attrition in the company.</li><li>Employees whose marital status is ‘single’ are more likely to leave the organization as compared to employees who are ‘married or ‘divorced’.</li><li>Employees whose age fall between 18–30 are more likely to leave the organization. Attrition rate reduces as the age of the employees increases.</li><li>Attrition rate reduces as monthly income increases.</li><li>Sales Representatives are lowest average earners in the organization.</li></ul><h4>Recommendations</h4><ul><li>Review business travel policy and take a survey on employees to get their opinion on business travels.</li><li>Adjust workload on employees to reduce overtime.</li><li>HR manager and department managers should have a sit down with employees with low job satisfaction, low job involvement and bad work -life balance to discuss causes and solutions.</li><li>Survey employees between the ages of 18 and 30 to understand their feeling and opinion on the organization and its culture</li><li>Review salary and job involvement of <em>Sales Representatives</em>.</li><li>Conduct exit interviews on employees leaving the organization to get personalized feedback on why each employee is leaving.</li><li>Add important dates like hire date and exit date to data to enable data analysts examine trends in attrition</li></ul><p><strong>References:</strong></p><ul><li><a href="https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset">Kaggle</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f96a8d8126" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Assessment in Python using Pandas]]></title>
            <link>https://medium.com/@ayersamuel07/data-assessment-in-python-using-pandas-b47318f42aef?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b47318f42aef</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Sat, 05 Nov 2022 12:46:37 GMT</pubDate>
            <atom:updated>2023-03-22T21:12:02.313Z</atom:updated>
            <content:encoded><![CDATA[<h4>So you’ve imported your data into a Pandas DataFrame in Jupyter Notebook, what’s next?</h4><h4>Introduction</h4><p>After importing your data into a Pandas Dataframe, you need to assess the data. Data assessment is basically examining data to see if it is fit and clean enough for its intended purpose. The purpose may be statistical analysis, visualizations or model building. Whatever the purpose, if the data is not rightly assessed, you risk drawing wrong conclusions from the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*dTimGlftxNolLUadwkB8VA.jpeg" /></figure><p>This article is aimed at beginners and mid-level data professionals looking to refresh their skills on data assessment. It covers Pandas functions for assessing data but not Pandas functions for cleaning data issues. However, links to articles for cleaning some of the issues are included.</p><p>Let’s look at the types of data assessment in Pandas and some data issues to look out for when assessing data. If you are already familiar with the types of assessment and the types of data issues, skip to <a href="#d57e">Pandas functions for data assessment</a>.</p><h4><strong>Types of Data Assessment</strong></h4><p>There are two ways of assessing data in Pandas. These are:</p><ul><li>Visual Assessment</li><li>Programmatic Assessment</li></ul><p>As the name implies, <strong>visual assessment</strong> is examining data by looking through the data. Minimum to no code is needed here. Visual assessment can be done in spreadsheet software like Microsoft Excel and Google Spreadsheet that display the data by default. However in Pandas, you’ll need to write one or two lines of code to display the data before you can visually examine the data.</p><p><strong>Programmatic assessment</strong> on the other hand, involves assessing data with code. There are some issues with data that can not be identified through visual examination especially when the data has lots of rows and columns. That is where programmatic assessment comes in. In programmatic assessment, you write code to extract certain characteristics of the data.</p><p>Whether you assess the data visually or programmatically, your aim is to detect any issues that affect the data’s fitness for purpose. Let’s look at some common data issues.</p><h4><strong>Data Issues</strong></h4><p>Data issues can be grouped under two major types. The two types are as follows:</p><p>· Tidiness issues</p><p>· Quality issues</p><p><strong>Data tidiness issues</strong> have to do with the structure of the data. Hadley Wickham, in his <a href="https://vita.had.co.nz/papers/tidy-data.pdf">paper on tidy data</a>, defined tidy data as data that meets the following conditions:</p><blockquote>· Every variable forms a column</blockquote><blockquote>· Every observation forms a row</blockquote><blockquote>· Every type of observational unit forms a table</blockquote><p>This definition has come to be accepted as the ‘rules’ of tidy data. When a data issue violates any of the rules of tidy data, that issue is a data tidiness issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jjzhy4KknPz9hJVnC_w7w.png" /><figcaption>Pictorial representation of the ‘rules’ of tidy data</figcaption></figure><p>The following are some data tidiness issues:</p><ul><li>Columns containing more than one variable.</li><li>Variables recorded as rows instead of columns.</li><li>Tables containing more than one observational unit.</li><li>Single variables spread across multiple columns.</li></ul><p><strong>Data quality issues</strong> are issues affecting the content of the data. Some common data quality issues include the following:</p><ul><li>Missing values</li><li>Duplicate values</li><li>Inconsistent formatting</li><li>Wrong spellings</li><li>Non-descriptive column labels</li></ul><p><strong>NB:</strong> These are common issues that affect data in general. However, there are data issues specific to certain industries. Therefore your assessment should be informed by the source of the data too.</p><h4><strong>Data Assessment Functions in Pandas</strong></h4><p>The functions covered in this article are as follows:</p><ul><li>df.head()</li><li>df.tail()</li><li>df.sample()</li><li>df.shape</li><li>df.info()</li><li>df.describe()</li><li>df.nunique()</li><li>df[col].value_counts()</li><li>df.isnull() and df.isnull().sum()</li><li>df.duplicated() and df.duplicated().sum()</li></ul><p><strong>NB:</strong> df is short for DataFrame and is the arbitrary name for naming DataFrames in Pandas. It can be replaced with the name assigned to the DataFrame.</p><p>Two datasets are used in the following paragraphs to demonstrate the Pandas functions.</p><ul><li>The <a href="https://drive.google.com/file/d/1dzMHlg4B5HnoanXZ1iWSEj5HOxPGr1DJ/view?usp=sharing">wine dataset</a> contains characteristics of various red wine samples.</li><li>The <a href="https://drive.google.com/file/d/1PqJ9f88raQUYR2xifiVv3AH8Ial4qMAe/view?usp=share_link">travel dataset</a> contains information on trips.</li></ul><p>Let’s look at each function.</p><h4><strong>df.head()</strong></h4><p>By default, df.head()displays the first 5 rows of the DataFrame. However, when you pass a number into the parenthesis, df.head()displays that number of rows from the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tAQkWq38la9IbOlrBr3o7g.png" /><figcaption>wine.head()</figcaption></figure><p>As shown in the image, wine.head()returned the first 5 rows in the wine DataFrame. Let’s pass a number into the parenthesis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CktOTo-bfvAlztmNdUZjaA.png" /><figcaption>wine.head(7)</figcaption></figure><p>Passing 7 into the parentheses returned the first 7 rows.</p><h4><strong>df.tail()</strong></h4><p>df.tail()is similar to df.head(). However, df.tail()returns the last 5 rows of the DataFrame. When a number is passed into the parenthesis, df.tail() returns that number of rows from the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XOgPIJEfrzIJFl3YfkebQ.png" /><figcaption>wine.tail()</figcaption></figure><p>wine.tail() returned the last 5 rows in the wine DataFrame.</p><h4><strong>df.sample()</strong></h4><p>By default, df.sample()returns a random row from the DataFrame. However, when you pass a number into the parenthesis, it returns that number of random rows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bm1tJsHbxZN82ky7Pv_Z7Q.png" /><figcaption>wine.sample()</figcaption></figure><p>The default df.sample()function returned a row with the index 633 from the wine DataFrame.</p><p>Let’s pass a number into the parenthesis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKK5hEUz6xO5g8OtudtMlA.png" /><figcaption>wine.sample(10)</figcaption></figure><p>Passing 10 into the parenthesis returned 10 random rows from the wine DataFrame.</p><p>For the full syntax of df.sample() check the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sample.html">Pandas Documentation.</a></p><p><strong>NB:</strong> df.head(), df.tail() , and df.sample() facilitate visual assessment. By scanning through the rows returned from these functions, you can identify some issues with the data if they exist. Look at this example calling df.head() on the travel DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfCouhx8cohpknyHH9mA1Q.png" /><figcaption>travel.head()</figcaption></figure><p>From the first five rows returned by travel.head(), you can identify missing values recorded as NaN (meaning ‘not a number’) in the `<em>FuelEconomy</em>` and `<em>Comments</em>` columns . Missing values are a data quality issue.</p><p><strong>NB:</strong> If you’re working in Jupyter Notebook, it is advisable to list all issues in a markdown cell for easy reference.</p><h4><strong>df.shape</strong></h4><p>df.shape returns the number of rows and columns in the DataFrame. Let’s call df.shape on the wine DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68XX07Sw15U_rVauwNr2fQ.png" /><figcaption>wine.shape</figcaption></figure><p>The result returned by wine.shape indicates that there are 1599 rows and 12 columns in the wine DataFrame.</p><h4><strong>df.info()</strong></h4><p>Calling df.info() on a DataFrame returns:</p><ul><li>The number of rows</li><li>The number of columns</li><li>The number of non-null rows for each column</li><li>The datatype of each column</li><li>The memory used by the DataFrame</li></ul><p>Let’s call this function on the travel DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJIoYAKme_cDZVB3ju_CQA.png" /><figcaption>travel.info()</figcaption></figure><p>In the travel dataset, there are:</p><ul><li>205 entries (rows)</li><li>13 columns</li></ul><p>By looking at the information returned by the function, you can identify a few issues with the data. The following are some of the issues:</p><ul><li>Wrong datatype for the <em>‘Date’ </em>column (data type of date columns should be Datetime not object)</li><li>Nulls in the ‘<em>FuelEconomy’</em> and ‘<em>Comments’</em> columns</li></ul><h4><strong>df.describe()</strong></h4><p>df.describe() returns descriptive statistics on the numerical columns in the DataFrame. The descriptive statistics returned by df.describe are as follows:</p><ul><li>Count of rows</li><li>Mean</li><li>Standard deviation</li><li>Minimum value</li><li>1st quartile</li><li>Median</li><li>3rd quartile</li><li>Maximum value</li></ul><p>Let’s call this function on the wine DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJihD5hi0FjgamrAm7YXXA.png" /><figcaption>wine.describe()</figcaption></figure><p>wine.describe() returned the descriptive statistics of the numeric columns in the wine DataFrame.</p><h4><strong>df.nunique()</strong></h4><p>df.nunique() returns the number of unique values in each column in the DataFrame. Replace col in df[col].nunique() with a column label to check the number of unique values in that column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7odCI4MUYRe5F0A7yAMbUA.png" /><figcaption>travel.nunique()</figcaption></figure><h4><strong>df[col].value_counts()</strong></h4><p>df[col].value_counts()takes in a column in the DataFrame . By default, df[col].value_counts() returns the frequency of each unique value in the column used in the function. The frequencies are arranged in descending order. Let’s call the default function on the ‘<em>GoingTo</em>’ column in the travel DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pM8T2xdECMIR9Zoh1H52kg.png" /><figcaption>travel[‘GoingTo’].value_counts()</figcaption></figure><p>travel[&#39;GoingTo&#39;].value_counts() returned the unique values (GSK, Home ) in the ‘<em>GoingTo</em>’ column with their frequencies in descending order.</p><p>df[col].value_counts() can be modified to return proportions instead of frequency. The syntax is df[col].value_counts(normalize=True) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FkcxjO39LjvtPAJWKJAPCQ.png" /><figcaption>travel[‘GoingTo’].value_counts(normalize=True)</figcaption></figure><p>Passing normalize=True in travel[&#39;GoingTo&#39;].value_counts() returned the proportion of the unique values (GSK , Home ).</p><p>For the full syntax, check the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.value_counts.html">Pandas Documentation</a>.</p><h4><strong>df.isnull() and df.isnull().sum()</strong></h4><p>df.isnull() returns Boolean values (True, False) the size of the DataFrame. df.isnull() returns True if the value is null and False if the value is non-null. Let’s call df.isnull() on the travel DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwgswsCQeztU7wrHYNvv0g.png" /><figcaption>travel.isnull()</figcaption></figure><p><strong>NB:</strong> Jupyter Notebook collapses some rows and columns. This is indicated with three dots.</p><p>In the ‘<em>FuelEconomy</em>’ and ‘<em>Comments</em>’ columns that had NaN , df.isnull() returned ‘<em>True</em>’ for those values and for non-null values, df.isnull() returned ‘<em>False</em>’.</p><p>df.isnull().sum() returns the sum of null values for each column in the DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqnZK-nAVYsEQ0O0MGHXcw.png" /><figcaption>travel.isnull().sum()</figcaption></figure><p>The results returned from travel.isnull().sum()indicate that there are 17 null values in the `<em>FuelEconomy</em>` column and 181 null values in the `<em>Comments</em>` column. The other columns do not have any null values.</p><p><strong>NB:</strong> By default, df.isnull() and df.isnull().sum() regard only NaN as null values. However, in real world data, missing values are sometimes denoted by empty strings(‘ ’) or ‘<em>None</em>’. By calling pandas.options.mode.use_inf_as_na=True , Pandas will treat empty strings as null values. For ‘<em>None</em>’, it is advisable to use df[col].value_counts() to check the unique values in a column to see if it includes ‘None’ as a value.</p><p>There are various ways of handling null values in Pandas. Two common ways are <a href="https://www.geeksforgeeks.org/python-pandas-dataframe-fillna-to-replace-null-values-in-dataframe/">filling null values</a> and <a href="https://www.geeksforgeeks.org/python-pandas-dataframe-dropna/">dropping missing values</a>.</p><h4><strong>df.duplicated()/df.duplicated().sum()</strong></h4><p>df.duplicated() returns True if a row is a duplicate and False if it is not a duplicate. By default, the first occurrence (row) of duplicates is not considered a duplicate so it gets ‘False’ while the other occurrences get ‘True’. That is, if there are five duplicated rows, the first row is not regarded as a duplicate. Therefore, df.duplicated() will return False for the first duplicated row but return True for the other four rows. The four rows are seen as duplicates of the first occurrence.</p><p>The function allows you to modify this so that instead of the first occurrence, the last occurrence is rather regarded as not a duplicate. Therefore if there are five duplicated rows, only the first four rows will be flagged as duplicates. The syntax for this is df.duplicated(keep=&#39;last&#39;) .</p><p>Instead of keeping the first or last occurrence as not a duplicate, the function can also be modified to regard all occurrences as duplicates and hence, return ‘True’ for all occurrences. Therefore if there are five duplicated rows, all five rows will be flagged as duplicates. The syntax is df.duplicated(keep=False) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PnmpKOyfZlcaSxAQB3yP5Q.png" /><figcaption>travel.duplicated()</figcaption></figure><p>Because Pandas collapses columns and rows, df.duplicated() may not display the entire rows depending on the size of the data. This can be resolved by using the df.duplicated().sum() function to display the number of duplicates in the entire DataFrame rather than going through the ‘<em>True</em>’ and ‘<em>False</em>’ returned by df.duplicated().</p><p>df.duplicated().sum() returns a number that indicates the number of duplicate rows in the DataFrame. If the function returns 0 then there are no duplicates rows in the DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5QIV2ZQQehYp6g4OUJoBg.png" /><figcaption>travel.duplicated().sum()</figcaption></figure><p>There are no duplicates in the travel DataFrame.</p><p>For the full syntax, check the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.duplicated.html">Pandas Documentation</a>.</p><p>For information about dealing with duplicates, check <a href="https://www.geeksforgeeks.org/python-pandas-dataframe-drop_duplicates/">dropping duplicates</a> by GeeksforGeeks.</p><h4>Conclusion</h4><p>Now that you know the Pandas functions for assessing a DataFrame and some issues to look out for when assessing data, you can apply them to your own DataFrame. The depth of your assessment is dependent on the source and purpose of the data.</p><h4>References</h4><ul><li><a href="https://vita.had.co.nz/papers/tidy-data.pdf">Tidy data by Hadley Wickham</a></li><li><a href="https://pandas.pydata.org/pandas-docs/stable/index.html">Pandas Documentation</a></li><li><a href="https://www.geeksforgeeks.org/">GeeksforGeeks</a></li><li><a href="https://www.udacity.com/course/data-analyst-nanodegree--nd002?utm_source=gsem_brand&amp;utm_medium=ads_r&amp;utm_campaign=12908932988_c_individuals&amp;utm_term=124509197511&amp;utm_keyword=data%20analysis%20udacity_e&amp;gclid=Cj0KCQjwwfiaBhC7ARIsAGvcPe7KWt1hk9CFMWwE-4mRNpn-tuA7IZ42YlLXR7ZkLRdjzqy7Q_Bp-xcaAuMpEALw_wcB">Udacity Data Analyst Nanodegree</a></li></ul><p>For any inquiries, reach me on LinkedIn, <a href="https://www.linkedin.com/in/samuel-t-ayer-3a278b221/">Samuel Ayer</a> or via email, ayersamuel210@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b47318f42aef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Wrangling and Analysis -  Insights from WeRateDogs Twitter Archive]]></title>
            <link>https://medium.com/@ayersamuel07/data-wrangling-and-analysis-insights-from-weratedogs-twitter-archive-28bc9d3862c9?source=rss-eae3a06310fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/28bc9d3862c9</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Samuel Ayer]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 15:07:25 GMT</pubDate>
            <atom:updated>2022-10-28T11:53:24.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Wrangling and Analysis - Insights from WeRateDogs Twitter Archive</h3><p><strong>About Project</strong></p><p><a href="https://twitter.com/dog_rates">WeRateDogs</a> is a twitter user that rates dogs with humorous comments about the dogs. For this project, I analyzed their tweet archive from 15th November 2015 to 1st August 2017. I gathered the data from 3 different sources.</p><p>The first file, the tweet archive, was given as a csv file by Udacity so I downloaded it manually. The second file containing image predictions was hosted on Udacity servers, so I downloaded it programmatically. The last file was additional information on the tweets, so I used a Twitter API to get the json information for each tweet ID. Then I read all three files into three different pandas dataframes.</p><h3>WeRateDogs® on Twitter: &quot;When you hear your owner say they need to hatch another egg, but you&#39;ve already been on 17 walks today. 10/10 pic.twitter.com/lFEoGqZ4oA / Twitter&quot;</h3><p>When you hear your owner say they need to hatch another egg, but you&#39;ve already been on 17 walks today. 10/10 pic.twitter.com/lFEoGqZ4oA</p><h4>Process</h4><p>The data was dirty and messy therefore I assessed the data both programmatically and visually and listed the issues. The issues included missing values and tweet ids that were retweets. I cleaned the columns in the three dataframes that were relevant to my analysis and visualizations. The Jupyter notebook used for the data wrangling and analysis has been uploaded to <a href="https://github.com/Outis09/Data-Wrangling-and-Analysis">GitHub</a>.</p><p>I combined the dataframes into one master dataframe which was used for the statistical analysis and visualizations. The following insights were derived from the analysis.</p><p><strong>Dog stage and rating</strong></p><p>There were four dog stages-i.e.- doggo, puppo, pupper and floofer. Some tweets had dogs with more than one stage so I labelled them as ‘multiple stages’. The description of each stage is given by WeRateDogs in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3e7Cc1ghFOEc702Nu3AkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwdTJmDIYoiAsetcF5TvEA.jpeg" /><figcaption>Doggo</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B4AZ2lnoMM2vtGowzHsP_Q.jpeg" /><figcaption>Pupper</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*ozSDSQeJb00BkLP1MWVMpg.jpeg" /><figcaption>Puppo</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*yBv_csLlP5RDv0cZRVv2Bw.jpeg" /><figcaption>Floofer</figcaption></figure><p>I compared the average rating of each dog stage and discovered that dogs of the puppo stage had the highest average rating.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*AkllxU-nAVsVTUnlzMcZTw.png" /></figure><p>I plotted this on a bar chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*aFZtwefwOymFgF0RFulx0Q.png" /></figure><p>The puppo stage is closely followed by the doggo stage. Dogs of the pupper stage received the lowest average rating.</p><p><strong>Dog stage and Favorites and Retweets</strong></p><p>I compared the dog stages in terms of favorites on a tweet and retweets.</p><p>I plotted the graph below to represent my findings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*7wgDvqIS1g5WIugw8Lix-g.png" /></figure><p>Dogs of the puppo stage were the most favorited while dogs of the pupper stage were the least favorited.</p><p>In terms of retweets, dogs of the doggo stage were the most retweeted.</p><p><strong>Image Number and Ratings</strong></p><p>During assessment of the data, I discovered an interesting comment by WeRateDogs which was a reply to another user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwD0MM8t6-A3LIw_DDSh5A.jpeg" /></figure><p>I decided to investigate the relationship between image number and retweets.</p><p>Below is a table showing the average rating for each image number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*5sbbAWkHxyodiddQ4XborQ.png" /></figure><p>NB: I used the ratings in decimals because the denominators were not the same.</p><p>I visualized the table in a bar graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*2w7FWMpVRQp7A-EZMJxeDA.png" /></figure><p>From the bar graph, I discovered that tweets with four images had the highest average rating. Perhaps because with more images, WeRateDogs could ‘polish a full analysis’.</p><p><strong>Dog breed distribution</strong></p><p>I sought to visualize the distribution of dog breeds as predicted by the image prediction algorithm used by Udacity. I plotted the top 10 dog breeds by frequency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*sMLIZ8lK-TQ81on__82X6w.png" /></figure><p>The most occurring dog breed was the golden retriever and it had a frequency of 138. Below is an image of a golden retriever.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*iRQA_soNMJ1-aFHBTXFuUw.jpeg" /><figcaption>Golden retriever</figcaption></figure><p><strong>Text Analysis</strong></p><p>I produced a word cloud in the image of the WeRateDogs Twitter display picture below. The word cloud consists of the most used words in the text of WeRateDogs’ tweets in the given timeframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*O7XbFcW6ylUB9YqxFrqw3g.png" /><figcaption>WeRateDogs Twitter display picture</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*4tnSyCJ1GBTGUGxakyaMhA.png" /><figcaption>Word cloud created using outline of dog in WeRateDogs display picture</figcaption></figure><p>The Jupyter notebook containing the codes, analysis and all visualizations can be accessed on <a href="https://github.com/Outis09">my GitHub.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28bc9d3862c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>