Pandas - Dropping rows with missing data in a DataFrame using dropna()
Pandas: Data Cleaning and Preprocessing Exercise-2 with Solution
Write a Pandas program to drop rows with missing data.
This exercise demonstrates how to drop rows that contain missing values using the dropna() function.
Sample Solution :
Code :
Output:
Name Age Salary 0 David 25.0 50000.0
Explanation:
- Created a DataFrame with missing values.
- Used dropna() to remove rows that have any missing values.
- Displayed the DataFrame with the rows containing missing values dropped.
Python-Pandas Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics