ā¹ļø Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://sentry.io/answers/remove-dataframe-rows-with-missing-values-in-python/ |
| Last Crawled | 2026-04-08 07:39:46 (7 hours ago) |
| First Indexed | 2024-02-02 05:01:22 (2 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Remove DataFrame rows with missing values in Python | Sentry |
| Meta Description | Sentry helps developers monitor and fix crashes in real time. Get the details you need to resolve the most important issues quickly. |
| Meta Canonical | null |
| Boilerpipe Text | The Problem
In Pandas, how do I remove DataFrame rows that contain
None
or
NaN
across all columns? How can I do this when these values are present in only some columns?
The Solution
We can achieve both of these results using the
DataFrame.dropna
method. For example:
import
pandas
from
numpy
import
nan
df
=
pandas
.
DataFrame
(
{
"Test 1"
:
[
90
,
10
,
nan
,
nan
]
,
"Test 2"
:
[
41
,
nan
,
32
,
nan
]
,
"Test 3"
:
[
89
,
35
,
72
,
nan
]
,
"Test 4"
:
[
52
,
nan
,
nan
,
nan
]
,
}
)
print
(
df
)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
# 3 NaN NaN NaN NaN
df_no_empty_rows
=
df
.
dropna
(
how
=
"all"
)
# drop rows containing all NaNs
print
(
df_no_empty_rows
)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
df_no_empty_values
=
df
.
dropna
(
how
=
"any"
)
# drop rows containing any NaNs
print
(
df_no_empty_values
)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0 |
| Markdown | [Skip to main content](https://sentry.io/answers/remove-dataframe-rows-with-missing-values-in-python/#main-content)
Menu
Platform
Products
- [Error Monitoring](https://sentry.io/product/error-monitoring/)
- [Logs](https://sentry.io/product/logs/)
- [Session Replay](https://sentry.io/product/session-replay/)
- [Tracing](https://sentry.io/product/tracing/)
- [Seer NEW](https://sentry.io/product/seer/)
- [Profiling](https://sentry.io/product/profiling/)
- [AI Code Review NEW](https://sentry.io/product/seer/ai-code-review/)
- [Size Analysis NEW](https://sentry.io/product/size-analysis)
- [Cron Monitoring](https://sentry.io/product/cron-monitoring/)
- [Uptime Monitoring](https://sentry.io/product/uptime-monitoring/)
- [Sentry CLI NEW](https://cli.sentry.dev/)
Integrations
- [Github](https://sentry.io/integrations/github/)
- [Slack](https://sentry.io/integrations/slack/)
- [Sentry MCP NEW](https://mcp.sentry.dev/)
- [All Integrations](https://sentry.io/integrations/)
SDKs
- [Javascript](https://sentry.io/for/javascript/)
- [Python](https://sentry.io/for/python/)
- [React](https://sentry.io/for/react/)
- [Laravel](https://sentry.io/for/laravel/)
- [Next.js](https://sentry.io/for/nextjs/)
- [All SDKs](https://sentry.io/platforms/)
Solutions
### Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
Resources
Learn
- [Blog](https://blog.sentry.io/)
- [Changelog](https://sentry.io/changelog/)
- [Sandbox](https://sandbox.sentry.io/)
- [Resources](https://sentry.io/resources/)
- [Syntax](https://syntax.fm/)
- [Customers](https://sentry.io/customers/)
- [Cookbook](https://sentry.io/cookbook/)
Support
- [Contact Us](https://sentry.io/contact/enterprise/)
- [Help Center](https://help.sentry.io/)
- [Status](https://status.sentry.io/)
Hang out with us
- [Sentry Build](https://sentry.io/resources/sentry-build/)
- [Events](https://sentry.io/events/)
- [Merch](https://sentry.shop/)
[Docs](https://docs.sentry.io/)
[Pricing](https://sentry.io/pricing/)
[Sign In](https://sentry.io/auth/login/) [Get Demo](https://sentry.io/demo/) [Get Started](https://sentry.io/signup/)
- Platform
- Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
- Resources
- [Docs](https://docs.sentry.io/)
- [Pricing](https://sentry.io/pricing/)
[Sign In](https://sentry.io/auth/login/) [Get Demo](https://sentry.io/demo/) [Get Started](https://sentry.io/signup/)
[Sentry Answers](https://sentry.io/answers/) \> [Python](https://sentry.io/answers/python/) \> Remove DataFrame rows with missing values in Python
# Remove DataFrame rows with missing values in Python

David Y. ā
October 15, 2023
[jump to solution](https://sentry.io/answers/remove-dataframe-rows-with-missing-values-in-python/#the-solution)
## The Problem
In Pandas, how do I remove DataFrame rows that contain `None` or `NaN` across all columns? How can I do this when these values are present in only some columns?
## The Solution
We can achieve both of these results using the [`DataFrame.dropna`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html) method. For example:
```
import pandas
from numpy import nan
df = pandas.DataFrame(
{
"Test 1": [90, 10, nan, nan],
"Test 2": [41, nan, 32, nan],
"Test 3": [89, 35, 72, nan],
"Test 4": [52, nan, nan, nan],
}
)
print(df)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
# 3 NaN NaN NaN NaN
df_no_empty_rows = df.dropna(how="all") # drop rows containing all NaNs
print(df_no_empty_rows)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
df_no_empty_values = df.dropna(how="any") # drop rows containing any NaNs
print(df_no_empty_values)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
```
### More Python content
- Codecov [Python - Codecov (opens in a new tab)](https://about.codecov.io/language/python/)
- Sentry Blog [Logging in Python: A Developer's Guide (opens in a new tab)](https://blog.sentry.io/logging-in-python-a-developers-guide/#python-logging-best-practices)
- Sentry Blog [Python Performance Testing: A Comprehensive Guide (opens in a new tab)](https://blog.sentry.io/python-performance-testing-a-comprehensive-guide/)
- Engineering Blog [Testing in Hundreds of Environments (opens in a new tab)](https://sentry.engineering/blog/how-we-run-our-python-tests-in-hundreds-of-environments-really-fast)
-  [Listen to the Syntax Podcast (opens in a new tab)](https://syntax.fm/?utm_source=sentry&utm_medium=display&utm_campaign=syntax-na-podcastpromo&utm_content=logo-answers-rail-banner-listen)
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
[SEE EPISODES](https://syntax.fm/?utm_source=sentry&utm_medium=display&utm_campaign=syntax-na-podcastpromo&utm_content=logo-answers-rail-banner-listen)
## Related Answers
[Make a list of the column headers in a Python Pandas DataFrame](https://sentry.io/answers/make-a-list-of-the-column-headers-in-a-python-pandas-dataframe/)
David Y. ā
November 15, 2023
[Set individual font sizes for labels and titles in \`pyplot\` graphs](https://sentry.io/answers/set-individual-font-sizes-for-labels-and-titles-in-pyplot-graphs/)
David Y. ā
November 15, 2023
[Logical AND (&&) in Python](https://sentry.io/answers/logical-and-in-python/)
David Y. ā
May 15, 2023
[Split a string into a list of words in Python](https://sentry.io/answers/split-a-string-into-a-list-of-words-in-python/)
David Y. ā
June 15, 2024
Considered "not bad" by 4 million developers and more than 150,000 organizations worldwide, Sentry provides code-level observability to many of the world's best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
[learn more about sentry](https://sentry.io/) [join our discord](https://discord.com/invite/sentry)

### Company
- [About](https://sentry.io/about/)
- [Blog](https://blog.sentry.io/)
- [Careers](https://sentry.io/careers/)
- [Contact Us](https://sentry.io/contact/enterprise/)
- [Trust](https://sentry.io/trust/)
### Platform
- [Error Monitoring](https://sentry.io/product/error-monitoring/)
- [Tracing](https://sentry.io/product/tracing/)
- [Session Replay](https://sentry.io/product/session-replay/)
- [Seer](https://sentry.io/product/seer/)
- [Logs](https://sentry.io/product/logs/)
- [Uptime Monitoring](https://sentry.io/product/uptime-monitoring/)
- [Profiling](https://sentry.io/product/profiling/)
- [Cron Monitoring](https://sentry.io/product/cron-monitoring/)
- [Integrations](https://sentry.io/integrations/)
### Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
### Get Help
- [Docs](https://docs.sentry.io/)
- [Help Center](https://help.sentry.io/)
- [Status](https://status.sentry.io/)
- [Dev Resources](https://develop.sentry.dev/getting-started/)
[Terms](https://sentry.io/terms/) [Security & Compliance](https://sentry.io/security/) [Privacy](https://sentry.io/privacy/)
[ Twitter Menu Button](https://x.com/sentry/) [ Github Social Menu Button](https://github.com/getsentry/) [ LinkedIn Menu Button](https://linkedin.com/company/getsentry/) [ Discord Menu Button](https://discord.gg/sentry)
© 2026 ⢠Sentry is a registered Trademark of Functional Software, Inc. |
| Readable Markdown | ## The Problem
In Pandas, how do I remove DataFrame rows that contain `None` or `NaN` across all columns? How can I do this when these values are present in only some columns?
## The Solution
We can achieve both of these results using the [`DataFrame.dropna`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html) method. For example:
```
import pandas
from numpy import nan
df = pandas.DataFrame(
{
"Test 1": [90, 10, nan, nan],
"Test 2": [41, nan, 32, nan],
"Test 3": [89, 35, 72, nan],
"Test 4": [52, nan, nan, nan],
}
)
print(df)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
# 3 NaN NaN NaN NaN
df_no_empty_rows = df.dropna(how="all") # drop rows containing all NaNs
print(df_no_empty_rows)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
# 1 10.0 NaN 35.0 NaN
# 2 NaN 32.0 72.0 NaN
df_no_empty_values = df.dropna(how="any") # drop rows containing any NaNs
print(df_no_empty_values)
# output:
# Test 1 Test 2 Test 3 Test 4
# 0 90.0 41.0 89.0 52.0
``` |
| Shard | 147 (laksa) |
| Root Hash | 17800916657557307547 |
| Unparsed URL | io,sentry!/answers/remove-dataframe-rows-with-missing-values-in-python/ s443 |