ℹ️ 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.7 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://www.plus2net.com/python/pandas-dataframe-dropna.php |
| Last Crawled | 2026-03-29 08:36:31 (19 days ago) |
| First Indexed | 2020-05-03 15:07:41 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Python Pandas DataFrame dropna() to remove labels on given axis when any data found to be missing or NaN |
| Meta Description | Python Pandas dropna() to remove lables or columns along the axis if NA data is available |
| Meta Canonical | null |
| Boilerpipe Text | Python
Pandas
Pandas Data Cleaning
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju',
None
,None,'King','Alex'],
'ID':[1,2,3,
np.NaN
,5,6],
'MATH':[80,40,70,
np.NaN
,82,30],
'ENGLISH':[81,70,40,
np.NaN
,
np.NaN
,30]}
df = pd.DataFrame(data=my_dict)
print(df)
print(df.dropna()) # remove all rows with NaN or None values
Output is here
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
2
None
3.0 70.0 40.0
3
None NaN NaN NaN
4 King 5.0 82.0
NaN
5 Alex 6.0 30.0 30.0
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
5 Alex 6.0 30.0 30.0
dropna(): Remove rows or columns based on missing values #C01
dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
Return the Modified DataFrame ( if
inplace=True
).
axis
0 (default ) or 1, decide row or column to remove.
how
Takes values
any
or
all
. Check examples below.
thresh
int : Minimum NaN values required.
subset
Labels along other axis to consider
inplace
Boolean , along with method if value is True then original ( source ) dataframe is replaced after applying
dropna()
how
any : rows are removed if any value contains NaN
all : rows are removed if all values are contains NaN
print(df.dropna(how='any'))
2,3 and 4 numbered rows are removed as it contains NaN or None values ( at least one )
Output
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
5 Alex 6.0 30.0 30.0
We will use
how=all
, remove the row or column if
all
values contains NaN.
print(df.dropna(how='all'))
row 3 (having all NaN values) is dropped with axis=0, output
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
2 None 3.0 70.0 40.0
4 King 5.0 82.0 NaN
5 Alex 6.0 30.0 30.0
Remove the row if a perticular column has NaN value
print(df.dropna(axis=0,subset=['ENGLISH']))
Output
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
2 None 3.0 70.0 40.0
5 Alex 6.0 30.0 30.0
With axis=1 and how='any', all columns are deleted.
print(df.dropna(how='any',axis=1))
Output
Empty DataFrame
Columns: []
Index: [0, 1, 2, 3, 4, 5]
how=all
print(df.dropna(axis=1,how='all'))# Nothing will be removed.
Let us change the dataframe by keeping all NaN values to one column.
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju',None,None,'King','Alex'],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,None,np.NaN,np.NaN,np.NaN,None]}
df = pd.DataFrame(data=my_dict)
print(df)
print(df.dropna(axis=1,how='all')) #remove column if all data is NaN
Output : Column 'ENGLISH' is dropped as all are NaN with axis=1
NAME ID MATH
0 Ravi 1.0 80.0
1 Raju 2.0 40.0
2 None 3.0 70.0
3 None NaN NaN
4 King 5.0 82.0
5 Alex 6.0 30.0
thresh
Minimum NaN values required
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN]}
df = pd.DataFrame(data=my_dict)
df=df.dropna(how='any',axis=0,thresh=3)
print(df)
Output
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 NaN
1 Raju 2.0 40.0 NaN
2 Alex 3.0 70.0 NaN
4 King 5.0 82.0 NaN
Handling NaT values
NaT : Missing value in Date and time.
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[81,70,40,np.NaN,np.NaN,30],
'Entry':['1/1/2020','2/1/2020',pd.NaT,
pd.NaT,'5/1/2020','1/2/2020']
}
df = pd.DataFrame(data=my_dict)
print(df)
Remove the row if
Entry
column has NaT
df=df.dropna(axis=0,subset=['Entry'])
print(df)
Output
NAME ID MATH ENGLISH Entry
0 Ravi 1.0 80.0 81.0 1/1/2020
1 Raju 2.0 40.0 70.0 2/1/2020
4 King 5.0 82.0 NaN 5/1/2020
5 None 6.0 30.0 30.0 1/2/2020
inplace
We will use
inplace=True
so the original DataFrame is changed.
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN]}
df = pd.DataFrame(data=my_dict)
df.dropna(how='all',inplace=True,axis=1)
print(df)
Output ( ENGLISH column is removed )
NAME ID MATH
0 Ravi 1.0 80.0
1 Raju 2.0 40.0
2 Alex 3.0 70.0
3 None NaN NaN
4 King 5.0 82.0
5 None 6.0 30.0
Change the value of inplace to False and check the output
df.dropna(how='all',inplace=False,axis=1)
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 NaN
1 Raju 2.0 40.0 NaN
2 Alex 3.0 70.0 NaN
3 None NaN NaN NaN
4 King 5.0 82.0 NaN
5 None 6.0 30.0 NaN
Counting and identifying NaN values
We can count and display records with
NaN
by using
isnull()
isnull()
Removing rows or columns by using dropna()
Rows or columns can be filled by using fillna()
fillna()
Questions
Data Cleaning
contains() to display and delete row based on Conditions
loc
at
mask
Pandas
Pandas DataFrame
iloc - rows and columns by integers |
| Markdown | [](https://www.plus2net.com/)
- [plus2net Home](https://www.plus2net.com/)
- [HOME](https://www.plus2net.com/python/site_map.php)
[plus2net HOME](https://www.plus2net.com/) [SQL](https://www.plus2net.com/sql_tutorial/site_map.php) [HTML](https://www.plus2net.com/html_tutorial/site_map.php) [PHP](https://www.plus2net.com/php_tutorial/site_map.php) [JavaScript](https://www.plus2net.com/javascript_tutorial/site_map.php) [ASP](https://www.plus2net.com/asp-tutorial/site_map.php) [JQuery](https://www.plus2net.com/jquery/site_map.php) [PhotoShop](https://www.plus2net.com/ps-tutorial/index.php)
- [Python](https://www.plus2net.com/python/site_map.php)
[Python Home](https://www.plus2net.com/python/site_map.php) [Built in functions](https://www.plus2net.com/python/builtins.php) [date](https://www.plus2net.com/python/date.php) [List](https://www.plus2net.com/python/list.php) [Math](https://www.plus2net.com/python/math.php) [Online Classes](https://www.plus2net.com/python/online-class.php) [File Handling](https://www.plus2net.com/python/file.php) [Error Handling](https://www.plus2net.com/python/exception-handling.php) [Class Object](https://www.plus2net.com/python/class-object-method.php) [Samples](https://www.plus2net.com/python/sample-codes.php) [String](https://www.plus2net.com/python/string.php) [Variables](https://www.plus2net.com/python/variables.php)
[pdf ( ReportLab)](https://www.plus2net.com/python/pdf.php) [Tkinter](https://www.plus2net.com/python/tkinter.php) [Json](https://www.plus2net.com/python/json.php) [Numpy](https://www.plus2net.com/python/numpy.php) [Pandas](https://www.plus2net.com/python/pandas.php) [Image ( PIL)](https://www.plus2net.com/python/pillow.php) [Python & MySQL](https://www.plus2net.com/python/mysql.php) [SQLite](https://www.plus2net.com/python/sqlite.php)
- [Contact Us](https://www.plus2net.com/contactus.php)
# dropna(): Remove rows or columns based on missing values
1. [Python](https://www.plus2net.com/python/site_map.php)
2. [Pandas](https://www.plus2net.com/python/pandas.php)
3. [Pandas Data Cleaning](https://www.plus2net.com/python/pandas-data-cleaning.php)
```
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju',None,None,'King','Alex'],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[81,70,40,np.NaN,np.NaN,30]}
df = pd.DataFrame(data=my_dict)
print(df)
print(df.dropna()) # remove all rows with NaN or None values
```
Output is here
**dropna(): Remove rows or columns based on missing values \#C01**
```
dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
```
Return the Modified DataFrame ( if inplace=True ).
| | |
|---|---|
| `axis` | 0 (default ) or 1, decide row or column to remove. |
| `how` | Takes values *any* or *all*. Check examples below. |
| `thresh` | int : Minimum NaN values required. |
| `subset` | Labels along other axis to consider |
| `inplace` | Boolean , along with method if value is True then original ( source ) dataframe is replaced after applying *dropna()* |
## how
any : rows are removed if any value contains NaN
all : rows are removed if all values are contains NaN
```
print(df.dropna(how='any'))
```
2,3 and 4 numbered rows are removed as it contains NaN or None values ( at least one )
Output
```
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
5 Alex 6.0 30.0 30.0
```
We will use how=all , remove the row or column if **all** values contains NaN.
```
print(df.dropna(how='all'))
```
row 3 (having all NaN values) is dropped with axis=0, output
```
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
2 None 3.0 70.0 40.0
4 King 5.0 82.0 NaN
5 Alex 6.0 30.0 30.0
```
## Remove the row if a perticular column has NaN value
```
print(df.dropna(axis=0,subset=['ENGLISH']))
```
Output
```
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 81.0
1 Raju 2.0 40.0 70.0
2 None 3.0 70.0 40.0
5 Alex 6.0 30.0 30.0
```
## axis
With axis=1 and how='any', all columns are deleted.
```
print(df.dropna(how='any',axis=1))
```
Output
```
Empty DataFrame
Columns: []
Index: [0, 1, 2, 3, 4, 5]
```
how=all
```
print(df.dropna(axis=1,how='all'))# Nothing will be removed.
```
Let us change the dataframe by keeping all NaN values to one column.
```
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju',None,None,'King','Alex'],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,None,np.NaN,np.NaN,np.NaN,None]}
df = pd.DataFrame(data=my_dict)
print(df)
print(df.dropna(axis=1,how='all')) #remove column if all data is NaN
```
Output : Column 'ENGLISH' is dropped as all are NaN with axis=1
```
NAME ID MATH
0 Ravi 1.0 80.0
1 Raju 2.0 40.0
2 None 3.0 70.0
3 None NaN NaN
4 King 5.0 82.0
5 Alex 6.0 30.0
```
## thresh
Minimum NaN values required
```
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN]}
df = pd.DataFrame(data=my_dict)
df=df.dropna(how='any',axis=0,thresh=3)
print(df)
```
Output
```
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 NaN
1 Raju 2.0 40.0 NaN
2 Alex 3.0 70.0 NaN
4 King 5.0 82.0 NaN
```
Thresh is used for data cleaning where some threshold value of valid data is considered for retaining the rows or columns. [Check here to know how data cleaning is done by using thresh option](https://www.plus2net.com/python/pandas-dataframe-dropna-thresh.php).
## Handling NaT values
NaT : Missing value in Date and time.
```
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[81,70,40,np.NaN,np.NaN,30],
'Entry':['1/1/2020','2/1/2020',pd.NaT,
pd.NaT,'5/1/2020','1/2/2020']}
df = pd.DataFrame(data=my_dict)
print(df)
```
Remove the row if *Entry* column has NaT
```
df=df.dropna(axis=0,subset=['Entry'])
print(df)
```
Output
```
NAME ID MATH ENGLISH Entry
0 Ravi 1.0 80.0 81.0 1/1/2020
1 Raju 2.0 40.0 70.0 2/1/2020
4 King 5.0 82.0 NaN 5/1/2020
5 None 6.0 30.0 30.0 1/2/2020
```
## inplace
We will use inplace=True so the original DataFrame is changed.
```
import pandas as pd
import numpy as np
my_dict={'NAME':['Ravi','Raju','Alex',None,'King',None],
'ID':[1,2,3,np.NaN,5,6],
'MATH':[80,40,70,np.NaN,82,30],
'ENGLISH':[np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN]}
df = pd.DataFrame(data=my_dict)
df.dropna(how='all',inplace=True,axis=1)
print(df)
```
Output ( ENGLISH column is removed )
```
NAME ID MATH
0 Ravi 1.0 80.0
1 Raju 2.0 40.0
2 Alex 3.0 70.0
3 None NaN NaN
4 King 5.0 82.0
5 None 6.0 30.0
```
Change the value of inplace to False and check the output
```
df.dropna(how='all',inplace=False,axis=1)
```
```
NAME ID MATH ENGLISH
0 Ravi 1.0 80.0 NaN
1 Raju 2.0 40.0 NaN
2 Alex 3.0 70.0 NaN
3 None NaN NaN NaN
4 King 5.0 82.0 NaN
5 None 6.0 30.0 NaN
```
## Counting and identifying NaN values
We can count and display records with *NaN* by using *isnull()*
[« isnull()](https://www.plus2net.com/python/pandas-dataframe-isnull.php)
## Removing rows or columns by using dropna()
Rows or columns can be filled by using fillna()
[« fillna()](https://www.plus2net.com/python/pandas-dataframe-fillna.php)
## Questions
1. What is the dropna() function in Pandas?
2. What are the parameters of the dropna() function?
3. What is the difference between the \`how='any'\` and \`how='all'\` options in the dropna() function?
4. What is the \`thresh\` parameter in the dropna() function?
5. What is the \`subset\` parameter in the dropna() function?
6. What is the \`inplace\` parameter in the dropna() function?
7. What are the advantages and disadvantages of using the dropna() function?
8. How can you use the dropna() function to handle missing values in a Pandas DataFrame?
1. How does the dropna() function interact with the fillna() function?
2. How can you use the dropna() function to drop rows or columns that contain a certain percentage of missing values?
3. How can you use the dropna() function to drop rows or columns that contain only missing values?
[Data Cleaning](https://www.plus2net.com/python/pandas-data-cleaning.php)
[contains() to display and delete row based on Conditions »](https://www.plus2net.com/python/pandas-str-contains.php)
[« loc](https://www.plus2net.com/python/pandas-dataframe-loc.php) [« at](https://www.plus2net.com/python/pandas-dataframe-at.php) [« mask](https://www.plus2net.com/python/pandas-dataframe-mask.php)
[« Pandas](https://www.plus2net.com/python/pandas.php) [Pandas DataFrame](https://www.plus2net.com/python/pandas-dataframe.php) [iloc - rows and columns by integers »](https://www.plus2net.com/python/pandas-dataframe-iloc.php)
[« Numpy arrays](https://www.plus2net.com/python/numpy-ndarray.php) [Python & MySQL](https://www.plus2net.com/python/mysql.php) [Python- Tutorials »](https://www.plus2net.com/python/site_map.php)

##### Subhendu Mohapatra
Author
[🎥 Join me live on YouTube](https://www.youtube.com/channel/UCu1h_p0S9GPL9cnI3XvxjeA/live)
Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
[](https://www.linkedin.com/in/plus2net/) [](https://x.com/plus2net) [](https://www.youtube.com/@plus2net1)
[← Subscribe to our YouTube Channel here](https://www.youtube.com/channel/UCu1h_p0S9GPL9cnI3XvxjeA?sub_confirmation=1)
[← Subscribe to our YouTube Channel here](https://www.youtube.com/channel/UCu1h_p0S9GPL9cnI3XvxjeA?sub_confirmation=1)
This article is written by **plus2net.com** team. https://www.plus2net.com

**plus2net.com**
[Python Video Tutorials](https://www.plus2net.com/python/python-video.php)
[Python SQLite Video Tutorials](https://www.plus2net.com/python/python-sqlite-video.php)
[Python MySQL Video Tutorials](https://www.plus2net.com/python/mysql-video.php)
[Python Tkinter Video Tutorials](https://www.plus2net.com/python/tkinter-video.php)
✖
We use cookies to improve your browsing experience. . [Learn more](https://www.plus2net.com/cookies.php)
| | | | | | | | | |
|---|---|---|---|---|---|---|---|---|
| [HTML](https://www.plus2net.com/html_tutorial/site_map.php) | [MySQL](https://www.plus2net.com/sql_tutorial/site_map.php) | [PHP](https://www.plus2net.com/php_tutorial/site_map.php) | [JavaScript](https://www.plus2net.com/javascript_tutorial/site_map.php) | [ASP](https://www.plus2net.com/asp-tutorial/site_map.php) | [Photoshop](https://www.plus2net.com/ps-tutorial/index.php) | [Articles](https://www.plus2net.com/articles/index.php) | [**Contact us**](https://www.plus2net.com/contactus.php) | |
©2000-2026 plus2net.com All rights reserved worldwide [Privacy Policy](https://www.plus2net.com/privacy.htm) [Disclaimer](https://www.plus2net.com/terms.html)
| | | |
|---|---|---|
|  |  |  |
|  |  |  |
|  | |  |
|  | |  |
| | | |
|  |  | |
| | | |
|---|---|---|
|  |  |  |
|  |  |  |
|  | |  |
|  | |  |
| | | |
|  |  | | |
| Readable Markdown | [Python](https://www.plus2net.com/python/site_map.php) [Pandas](https://www.plus2net.com/python/pandas.php) [Pandas Data Cleaning](https://www.plus2net.com/python/pandas-data-cleaning.php) Output is here **dropna(): Remove rows or columns based on missing values \#C01** Return the Modified DataFrame ( if inplace=True ). `axis` 0 (default ) or 1, decide row or column to remove. `how` Takes values *any* or *all*. Check examples below. `thresh` int : Minimum NaN values required. `subset` Labels along other axis to consider `inplace` Boolean , along with method if value is True then original ( source ) dataframe is replaced after applying *dropna()* how any : rows are removed if any value contains NaN
all : rows are removed if all values are contains NaN 2,3 and 4 numbered rows are removed as it contains NaN or None values ( at least one )
Output We will use how=all , remove the row or column if **all** values contains NaN. row 3 (having all NaN values) is dropped with axis=0, output Remove the row if a perticular column has NaN value Output With axis=1 and how='any', all columns are deleted. Output how=all Let us change the dataframe by keeping all NaN values to one column. Output : Column 'ENGLISH' is dropped as all are NaN with axis=1 thresh Minimum NaN values required Output Handling NaT values NaT : Missing value in Date and time. Remove the row if *Entry* column has NaT Output inplace We will use inplace=True so the original DataFrame is changed. Output ( ENGLISH column is removed ) Change the value of inplace to False and check the output Counting and identifying NaN values We can count and display records with *NaN* by using *isnull()*
[isnull()](https://www.plus2net.com/python/pandas-dataframe-isnull.php) Removing rows or columns by using dropna() Rows or columns can be filled by using fillna()
[fillna()](https://www.plus2net.com/python/pandas-dataframe-fillna.php) Questions [Data Cleaning](https://www.plus2net.com/python/pandas-data-cleaning.php)
[contains() to display and delete row based on Conditions](https://www.plus2net.com/python/pandas-str-contains.php)
[loc](https://www.plus2net.com/python/pandas-dataframe-loc.php) [at](https://www.plus2net.com/python/pandas-dataframe-at.php) [mask](https://www.plus2net.com/python/pandas-dataframe-mask.php)
[Pandas](https://www.plus2net.com/python/pandas.php) [Pandas DataFrame](https://www.plus2net.com/python/pandas-dataframe.php) [iloc - rows and columns by integers](https://www.plus2net.com/python/pandas-dataframe-iloc.php) |
| Shard | 181 (laksa) |
| Root Hash | 727011249797570381 |
| Unparsed URL | com,plus2net!www,/python/pandas-dataframe-dropna.php s443 |