MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Dropping & Filling Missing Values (dropna, fillna)0%
Study MaterialsCheatsheet
PandasProgress 0%
1.1What is Pandas & Core Architecture1.2Pandas Installation & Environment Setup1.3Creating Series & DataFrames from Scratch
4.1Detecting Missing Values (isna, notna, isnull)4.2Dropping & Filling Missing Values (dropna, fillna)4.3Handling Duplicates & Data Type Conversions
HomeTutorialsPandasDropping & Filling Missing Values (dropna, fillna)
Handling Duplicates & Data Type Conversions

Dropping & Filling Missing Values (dropna, fillna)

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Strategies for Handling Missing Data

Once missing values are identified, a Data Analyst has two primary remedies:

  1. 1
    Deletion / Dropping (dropna): Remove rows or columns containing nulls (best when missingness is tiny, e.g. < 2%).
  2. 2
    Imputation / Filling (fillna): Replace missing values with domain-appropriate surrogates (mean, median, mode, forward-fill, or a sentinel constant).

2. Dropping Missing Data (df.dropna)

Key Parameters:

  • how='any' (Default): Drops a row if even one column is null.
  • how='all': Drops a row only if all columns are null.
  • subset=['ColA', 'ColB']: Checks for nulls only in specified critical columns.
  • axis=1: Drops entire columns containing nulls.
1import pandas as pd
2import numpy as np
3 
4df = pd.DataFrame({
5 'Name': ['Amit', 'Sunita', np.nan, 'Rohan'],
6 'Age': [24, np.nan, 29, 31],
7 'Salary': [50000, 62000, np.nan, 75000]
8})
9 
10# Drop rows where 'Name' is null (essential identifier)
11df_valid_names = df.dropna(subset=['Name'])
12 
13# Drop rows only if both Age and Salary are missing
14df_clean = df.dropna(subset=['Age', 'Salary'], how='all')

3. Imputing Missing Values (df.fillna)

A. Filling with a Constant

1# Fill missing names with 'Unknown'
2df['Name'] = df['Name'].fillna('Unknown')

B. Statistical Imputation (Mean & Median)

In financial and numerical datasets, imputing with the median is preferred over the mean because the median is robust to extreme outliers:

1# Impute Age with median age
2median_age = df['Age'].median()
3df['Age'] = df['Age'].fillna(median_age)
4 
5# Impute Salary with mean salary
6df['Salary'] = df['Salary'].fillna(df['Salary'].mean())

C. Sequential Imputation: Forward Fill & Backward Fill

In time-series and sensor data, use ffill() (propagate last valid observation forward) or bfill() (propagate next valid observation backward):

1# Forward fill
2df_filled = df.ffill()

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the default behavior of df.dropna()?
Question 2
How can you drop rows only when the 'Customer_Email' column is missing?
Question 3
Why is the median often preferred over the mean when imputing missing numeric values in skewed data (like salaries)?
Question 4
What does the df.ffill() method do?
Question 5
What parameter in fillna() allows updating the original DataFrame directly without reassigning?

Next Lesson

Handling Duplicates & Data Type Conversions

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Detecting Missing Values (isna, notna, isnull)Handling Duplicates & Data Type Conversions

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext