pandas.DataFrame.dropna() is used to drop/remove missing values from rows and columns, np.nan/pd.NaT (Null/None) are considered as missing values. Before we process the data, it is very important to clean up the data, as part of cleaning we would be required to identify the rows with Null/NaN/None values and drop them. This dropna() method comes in handy to drop rows with np.nan/pd.NaT values.
you have learned how to drop rows and columns with missing values by using pandas dropna() method. np.nan/pd.NaT (Null/None) are considered as missing values. None/NaN values are one of the major problems in Data Analysis hence before we process either you need to remove rows that have NaN values or replace NaN with empty for String and replace NaN with zero for numeric columns.
Syntax: pandas.DataFrame.dropna(axis = 0, how =’any’, thresh = None, subset = None, inplace=False)
Purpose: To remove the missing values from a DataFrame.
Parameters:
axis:0 or 1 (default: 0). Specifies the orientation in which the missing values should be looked for. Pass the value 0 to this parameter search down the rows. Pass the value 1 to this parameter to look across columns.
how:‘any’ or ‘all’ (default:’any’). If it is set to ‘any’, the row/column that has atleast one missing value will be dropped. If it is set to ‘all’, only the rows/columns in which all values are missing will be dropped.
thresh:Integer (default: None). Maximum number of missing values in a row or column which will be ignored by this function.
subset:array (default: None). It is used to specify the particular labels along the axis which is not specified in the axis parameter in which missing values should be looked for.
inplace:Boolean (default: False). Denotes if the missing values should be dropped in the original DataFrame or if a new DataFrame having the missing values dropped should be returned.
Returns: If inplace is set to ‘True’ then None. If it is set to ‘False’, then a DataFrame.
Practical Tips
In case of memory constraints, use the inplace parameter. Set its value as True so that the changes will take place in the original DataFrame itself and a new DataFrame will not be created.
Please keep in mind that while dropping rows or columns using the how parameter and setting its value as ‘all’ , the function will remove only those labels where all its values are missing or null values.
While removing columns, you can also pass row labels to the subset parameter to search for rows that contain missing values.
background music : Music from Tunetank.com
Decibel - Sweet Heat (Copyright Free Music)
Download free: https://tunetank.com/track/4231-sweet...