Handling Missing Values: Dropping as a Solution
This video shows how to visualize missing data with a seaborn heatmap and decide whether to drop rows or columns to clean a loan dataset in Python.
Not every missing value needs to be filled in. Sometimes the simplest and most defensible move is to drop the row or column entirely, and this video walks through exactly when and how to do that using a loan dataset in Google Colab.
Setting up and loading the data
The workflow starts in Google Colab, or alternatively Jupyter Notebook, importing pandas and matplotlib before loading the dataset with pandas' Excel-reading function. A head(4) call returns just the first four rows for a quick look, revealing columns like age, time, status, and telephone, a mix of numerical and categorical data, with both null and non-null values present throughout.
Counting the missing values
Running isnull().sum() shows exactly how many missing values sit in each column. In this dataset, a column like "time employ" shows two missing values, while "home expense" shows four, and so on for the rest of the columns. That count alone helps decide which columns are even worth keeping.
Visualizing the gaps
To get a clearer picture of where the missing data actually sits, the video uses the seaborn library to build a heatmap: sns.heatmap(dataset.isnull()) followed by plt.show(). With 425 rows in the dataset, the heatmap renders every column as a strip, showing non-null data in black and null values in a light cream color. This visual makes it immediately obvious which columns are riddled with gaps and which are mostly complete.
Deciding what to drop
Whether to drop by column or by row depends entirely on the dataset and what matters more for the analysis: preserving rows or preserving columns. In this example, the home expense column stands out as having more null values than the others, making it a reasonable candidate to drop entirely.
Dropping a column
Dropping the column uses drop with the column name specified, home expense in this case, along with inplace=True, which updates the existing dataset directly rather than creating a separate copy. Checking the dataset afterward confirms that the home expense column no longer appears at all.
Dropping rows instead
For rows where too many null values are present, the alternative is dropna applied at the row level. After dropping those rows, the resulting dataset, checked again with the heatmap visualization, shows no null values remaining anywhere in the graph, confirming the cleaning was successful.
Key takeaways
- Dropping missing data is a valid strategy alongside imputation, particularly when a column or row has too many gaps to fill reliably.
- A seaborn heatmap of isnull() values gives a fast visual read on where missing data concentrates across a dataset.
- Dropping a column uses drop(columns=...) with inplace=True to update the dataset directly.
- Dropping rows uses dropna(), removing records where too much data is missing.
- The choice between dropping by row or by column depends on which dimension of the data matters more for the analysis at hand.
Who this is for
This video is a practical starting point for anyone learning basic data cleaning workflows in pandas. It rounds out a Humanitarians AI series on missing value strategies that also covers scikit-learn's SimpleImputer and categorical imputation with fillna, backward filling, and forward filling.
Full transcript(auto-generated, with timestamps)
[0:00]We will learn about how we can clean our data by dropping a missing value in our data set so for that you need Jupiter notebook or Google collab platform to write your code so I'm using a Google collab here so very first step is you need to import the libraries that is penda zond met plot live afterward you need to load the data set for that I using this penda function that is pd. read Axel and my file name now I want to check only the top four rows so here I'm using this data set. head4 function then it returns four rows only so in this sta Set uh there are
[0:55]Different different columns like age time status telephone and so on numerical and categorial what type of data are present in this particular data set also there are null nonnull values are there so if you want to check how many null values are present in the particular data set so just only need to put is null function do su function and you can easily check how many null values are present toward that particular column for example time employ two has two null values and home expense of four and so on now if you want to check all these null value in a graphical form so for
[1:46]That uh we are using here C library and I'm using this SNS do heat map data set is null this function and plot. show this will show show the graphical representation of those columns here so like here you see the number of rows are 425 and these are the columns and the data which are not null which is showing here in a black color and the light cream color data is your null values present in your data set so now you have to decide like what how you want to delete your data by column wise or rowwise it totally depend on your data set
[2:56]Like if your rows are more important or column what kind of data is more important to you so if you want to delete your data in a column wise let's suppose so in your data set you see like home expense have more null values so let's suppose I want to delete this data so you can simply put drop column home expense your column name and here I put in place equal to true that means you don't want to create another data file for that particular data set this means you are updating your data in exis in file so now if you check does this data deleted or not so
[4:11]Here you see there is no home expense column present in your data set right now after dropping it and if you want to delete some rows where you thought that more null values are present then you simply do drw p a and this is the representation after deleting those missing values from rows and columns so this is the final representation here so you see there is no null value present this time in this graph so that's how you can delete your row or column missing values simply by doing this these functions so yeah thanks
More videos
2:08Bridging the Pixel Gap in Browser Automation.
2:23How One Narrow Safety Rule Can Make an AI Less Safe Everywhere Else.
2:04Why splitting a chunk from its document makes it retrieve for the wrong question
4:20Three You Can Take Back. One You Can't.
2:21Why a 50-turn agent pays for the same screenshot 35 times unless it caches the pixels
1:53