<?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 Muskan Adnan on Medium]]></title>
        <description><![CDATA[Stories by Muskan Adnan on Medium]]></description>
        <link>https://medium.com/@muskanadnan07?source=rss-357ca7954902------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_4KdfuLQIzoGAwsWxhPyVQ.jpeg</url>
            <title>Stories by Muskan Adnan on Medium</title>
            <link>https://medium.com/@muskanadnan07?source=rss-357ca7954902------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:17:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muskanadnan07/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[How I Finally Understood Missing Data in Pandas]]></title>
            <link>https://medium.com/@muskanadnan07/how-i-finally-understood-missing-data-in-pandas-423f0b9e8de4?source=rss-357ca7954902------2</link>
            <guid isPermaLink="false">https://medium.com/p/423f0b9e8de4</guid>
            <category><![CDATA[python-libraries]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-science-projects]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <dc:creator><![CDATA[Muskan Adnan]]></dc:creator>
            <pubDate>Wed, 25 Nov 2026 12:23:51 GMT</pubDate>
            <atom:updated>2026-11-25T12:23:51.320Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A beginner’s notes on NaN values, what they mean, and how to deal with them.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wm3FTnAjNOL10m1y" /></figure><p>The first time I loaded a real dataset into Pandas, I felt confident. I had finished a few tutorials, I knew read_csv, and I was ready to build my first model. Then I ran df.info() and saw that half my columns had fewer rows than the others.</p><p>Missing data. Nobody had warned me it would be this common.</p><p>If you are learning data science, you will meet missing values in almost every project. In this article, I will share how I learned to find them, understand them, and handle them, with simple code you can try yourself.</p><h3>Why Missing Data Matters?</h3><p>Missing values are not just an annoyance. They can break your code, distort your averages, and quietly reduce the quality of your model. Many machine learning algorithms will simply throw an error if they see a NaN. Others will run, but give you misleading results.</p><p>The key lesson I learned early: <strong>you should never fill or delete missing values without first asking why they are missing.</strong></p><h3>Step 1: Find the Missing Values</h3><p>Let’s use a small example dataset.</p><pre>import pandas as pd<br>import numpy as np<br><br>data = {<br>    &quot;name&quot;: [&quot;Ali&quot;, &quot;Sara&quot;, &quot;Ahmed&quot;, &quot;Hina&quot;, &quot;Usman&quot;],<br>    &quot;age&quot;: [23, np.nan, 31, 28, np.nan],<br>    &quot;city&quot;: [&quot;Karachi&quot;, &quot;Lahore&quot;, None, &quot;Karachi&quot;, &quot;Islamabad&quot;],<br>    &quot;salary&quot;: [50000, 62000, 58000, np.nan, 71000]<br>}<br><br>df = pd.DataFrame(data)<br>print(df)</pre><p>The fastest way to see what is missing is:</p><pre>df.isnull().sum()</pre><p>This gives you the number of missing values in each column. For a bigger dataset, I also like to check the percentage:</p><pre>(df.isnull().mean() * 100).round(1)</pre><p>A column with 2% missing values is a very different problem from a column with 60% missing values. That percentage helps you decide what to do next.</p><h3>Step 2: Understand Why the Data Is Missing</h3><p>This was the part that changed how I think. Missing data usually falls into three broad types:</p><ul><li><strong>Missing completely at random:</strong> The gap has no pattern. For example, someone forgot to fill one field in a form.</li><li><strong>Missing at random:</strong> The gap depends on another column. For example, younger respondents skip the income question more often.</li><li><strong>Missing not at random:</strong> The gap depends on the missing value itself. For example, people with very high incomes choose not to report them.</li></ul><p>You don’t need to memorize the formal names. Just remember to ask: <em>is there a pattern behind these blanks?</em> A quick way to check is to compare groups:</p><pre>df[df[&quot;age&quot;].isnull()]</pre><p>Look at the rows with missing ages. Do they share something, like the same city or a similar salary range? If yes, the missingness itself carries information.</p><h3>Step 3: Choose a Strategy</h3><p>There is no single correct answer. Here are the three approaches I use most.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhmJMst2c9BRIAJG1WitTg.png" /></figure><p>A column that is mostly empty gets dropped; otherwise its type decides the fill.</p><h3>Option 1: Drop the missing rows</h3><pre>df_dropped = df.dropna()</pre><p>This is simple, but be careful. In our small example, it would remove most of our rows. Dropping makes sense only when very few rows are affected, or when the missing column is essential and cannot be estimated.</p><p>You can also drop a whole column if most of it is empty:</p><pre>df_cols = df.dropna(axis=1, thresh=4)</pre><p>Here thresh=4 keeps only the columns that have at least 4 non-missing values.</p><h3>Option 2: Fill with a statistic</h3><p>For numeric columns, the mean or median is the common choice.</p><pre>df[&quot;age&quot;] = df[&quot;age&quot;].fillna(df[&quot;age&quot;].median())<br>df[&quot;salary&quot;] = df[&quot;salary&quot;].fillna(df[&quot;salary&quot;].median())</pre><p>I prefer the <strong>median</strong> when the data has outliers, because a few very large salaries can pull the mean far away from what is typical.</p><p>For categorical columns, use the most frequent value (the mode):</p><pre>df[&quot;city&quot;] = df[&quot;city&quot;].fillna(df[&quot;city&quot;].mode()[0])</pre><h3>Option 3: Fill using related information</h3><p>Sometimes a smarter fill is possible. For example, you can fill missing salaries with the average salary of the same city:</p><pre>df[&quot;salary&quot;] = df[&quot;salary&quot;].fillna(<br>    df.groupby(&quot;city&quot;)[&quot;salary&quot;].transform(&quot;median&quot;)<br>)</pre><p>This respects the structure in your data instead of treating every row the same.</p><h3>Step 4: Keep a Record of What You Filled</h3><p>Here is a habit I wish I had learned sooner. Before filling, create a flag column:</p><pre>df[&quot;age_was_missing&quot;] = df[&quot;age&quot;].isnull()</pre><p>Now, if the fact that age was missing turns out to be useful, your model can learn from it. It also makes your work transparent: anyone reading your notebook can see exactly which values were originally real and which were filled.</p><h3>Common Mistakes I Made</h3><ol><li><strong>Filling before splitting the data.</strong> If you calculate the mean from the full dataset and then split into train and test sets, information from the test set leaks into training. Always split first, then calculate fill values from the training set only.</li><li><strong>Using the mean on skewed data.</strong> Income, prices, and similar columns usually have outliers. Median is safer.</li><li><strong>Treating zero as missing, or missing as zero.</strong> A zero is a real value. A blank is unknown. Mixing them up changes your analysis.</li><li><strong>Deleting too quickly.</strong> Dropping rows feels clean, but you may be throwing away useful information and biasing your sample.</li></ol><h3>A Simple Checklist</h3><p>Whenever I get a new dataset now, I follow this routine:</p><ul><li>Check how many values are missing in each column.</li><li>Look at the percentage, not just the count.</li><li>Ask why the values might be missing.</li><li>Choose a strategy that fits the column type and the problem.</li><li>Add a flag column when the missingness might matter.</li><li>Document every decision in the notebook.</li></ul><h3>Final Thoughts</h3><p>Missing data taught me that data science is not only about algorithms. A large part of the job is careful thinking about the data before any model is trained. Pandas gives you the tools, but the judgment about <em>which tool to use</em> comes from understanding your data and your problem.</p><p>If you are just starting out, try this: take any messy public dataset, such as one from Kaggle, and practice finding and handling missing values with at least two different strategies. Compare the results. You will learn more from that exercise than from reading ten tutorials.</p><p>Thanks for reading. If this helped you, I would love to hear which part of data cleaning you find most confusing, and I may write about it next.</p><p>You can see my data science projects at [<a href="https://muskanadnan07-svg.github.io/">https://muskanadnan07-svg.github.io/</a>].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=423f0b9e8de4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Average Lied to Me: The Hidden Stories Behind Data]]></title>
            <link>https://medium.com/@muskanadnan07/the-average-lied-to-me-the-hidden-stories-behind-data-59c0c8ffe522?source=rss-357ca7954902------2</link>
            <guid isPermaLink="false">https://medium.com/p/59c0c8ffe522</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Muskan Adnan]]></dc:creator>
            <pubDate>Fri, 20 Nov 2026 17:50:08 GMT</pubDate>
            <atom:updated>2026-11-20T17:50:08.019Z</atom:updated>
            <content:encoded><![CDATA[<p><em>What I learned as a data science beginner when a single number turned out to be hiding the real story.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L32iBD1CTiTaABEkYGAj_Q.jpeg" /></figure><blockquote><em>The Hidden Stories Behind Data: Why Numbers Are More Powerful Than We Think</em></blockquote><p>When I started learning data science, I believed numbers were simple. A number was a fact. If someone said “the average salary in this company is $100,000,” I pictured a team of people all earning roughly that much.</p><p>Then I opened my first real dataset, and that belief fell apart.</p><h3>One number, many realities</h3><p>Imagine a small company with ten employees. Nine of them earn $40,000 a year. The tenth, the founder, earns $1,000,000.</p><p>The average salary is $136,000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERVj3cB3JTnXhI4BaEsbDg.png" /></figure><p>Technically, that number is correct. But it describes nobody in the company. Nine out of ten people earn less than a third of it. The average isn’t lying, exactly. It’s just answering a different question from the one you thought you were asking.</p><p>This is the first lesson data teaches you: <strong>a summary is a compression, and compression always loses something.</strong> The question is whether you noticed what was lost.</p><p>Now look at the median, the middle value. It’s $40,000. That one number tells a far more honest story about the typical employee. Same data, two numbers, two completely different impressions.</p><p>Here’s how you can see this in a few lines of Python:</p><pre>import pandas as pd<br><br>salaries = pd.Series([40000] * 9 + [1000000])<br><br>print(&quot;Mean:  &quot;, salaries.mean())    # 136000.0<br><br>print(&quot;Median:&quot;, salaries.median())  # 40000.0</pre><p><em>Two lines of output, and already the story has changed.</em></p><h3>When the whole is the opposite of its parts</h3><p>The average is a gentle trap. The next one is nastier.</p><p>There is a famous statistical effect called <strong>Simpson’s paradox</strong>, where a trend that appears in a whole dataset reverses when you split the data into groups.</p><p>Here’s a simplified version. Two hospitals treat the same condition:</p><h4>Hospital A Hospital B</h4><p>Overall success rate: 80% 85%</p><p>On the surface, Hospital B looks better. If you were choosing where to go, you’d pick B.</p><p>But now split patients by severity:</p><h4><strong>Hospital A Hospital B</strong></h4><p>Mild cases: 95% 90%</p><p>Severe cases: 70% 60%</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>Hospital A is better for mild cases. Hospital A is <em>also</em> better for severe cases. Yet Hospital B has the higher overall rate, because it happens to treat mostly mild cases, which are easier to succeed with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZVYYqMcucMel-pR99RkZQ.png" /></figure><p>The overall number said one thing. Every subgroup said the opposite. If you only looked at the headline figure, you would make the wrong decision, and you would feel completely confident doing it.</p><h3>Why this matters beyond statistics</h3><ul><li><strong>In news headlines.</strong> “Crime is up 20%” can mean very different things depending on the baseline, the time period and the area.</li><li><strong>In business dashboards.</strong> A rising overall conversion rate can hide the fact that your best customer segment is quietly leaving.</li><li><strong>In health and education.</strong> Averages over mixed groups can hide who is actually being helped and who is being left behind.</li></ul><p>In each case, the data is not false. The <em>interpretation</em> is incomplete. And incomplete interpretation is far more dangerous than obviously wrong data, because it looks like the truth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_5e9rHRpnt2QVqGLjSTdw.jpeg" /></figure><h3>The habits that changed how I look at data</h3><p>After running into these traps, I started building a few small habits. They have saved me from drawing wrong conclusions more than once.</p><p><strong>1. Never trust a single number.</strong> Always ask: what else describes this data? Look at the mean <em>and</em> the median. Look at the spread, not just the center.</p><p><strong>2. Plot before you conclude.</strong> A histogram or box plot takes seconds and often reveals outliers, clusters or strange shapes that a summary statistic hides.</p><pre>import matplotlib.pyplot as plt<br><br>salaries.plot(kind=&quot;hist&quot;, bins=10)<br>plt.title(&quot;Salary distribution&quot;)<br>plt.xlabel(&quot;Salary&quot;)<br>plt.show()</pre><p><strong>3. Break it into groups.</strong> Whenever you see an overall trend, ask whether it holds inside each subgroup. If it flips, you’ve found a hidden story.</p><p><strong>4. Ask who is missing.</strong> Every dataset is a sample of reality. Who wasn’t surveyed? Which cases were never recorded? What a dataset leaves out can matter as much as what it includes.</p><p><strong>5. Stay curious about surprises.</strong> When a result looks too clean or too shocking, that’s usually a signal to dig deeper, not to publish.</p><h3>Numbers are powerful, but only if we read them well</h3><p>I used to think the power of data was in the numbers themselves. Now I think it’s in the questions we ask of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*YuS5t0PIp6diFvctlyrgoA.jpeg" /></figure><p>A number can inform us or mislead us, and often it does both at the same time. The difference isn’t in the data. It’s in whether someone took the time to look behind it.</p><p>That’s what makes data science exciting to me. It isn’t just about calculating things. It’s about learning to hear the story the numbers are trying to tell, and noticing when the loudest number is drowning out the real one.</p><p>So the next time you see a statistic, an average, a percentage or a chart, pause for a moment and ask:</p><p><strong>What story is this number hiding?</strong></p><p>……………………………………………………………………………………………….</p><p><em>I’m currently learning data science and writing about what I discover along the way. If you enjoyed this, follow along for more beginner-friendly lessons from the journey.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59c0c8ffe522" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>