Learn Before
Concept
Pandas .dropna()
This function removes any missing values from a dataframe.
- Using the axis parameter (0 for indices and 1 for columns) you can determine where you would like to drop values from.
- The how parameter (any or all) determines whether you want to drop rows or columns with any NA values (any) or all NA values (all)
- The thresh parameter is optional but determines if you want to keep rows or columns with at least that many non-NA values.
#Drops rows with at least one NA value df.dropna() #Drops columns with at least one NA value df.dropna(axis = 1) #Drops rows with all values missing df.dropna(how = 'all) #Keeps rows only with at least 3 non NA values df.dropna(thresh = 3)
0
1
Updated 2021-05-25
Tags
Python Programming Language
Data Science