Pandas dropna in Python Tutorial with Example

Learn Pandas dropna in Python Tutorial with Example. The csv file has null values which are displayed as NaN in Data Frame. Pandas dropna() method allows the user to analyze and drop Rows/Columns with Null values in different ways.

dropna in python pandas Syntax:


           dataframeName.dropna (axis=0, how=’any’, thresh=none, subset=none, inplace=false)
Parameters:-

Axis: - It will take the int/string values for the rows and columns.
How:-It will take the string values of two kinds.
Thresh:-Takes the integer value and tells the minimum amount of values to drop.
Subset: - It is an array which limits dropping process to pass through list of rows and column.
Inplace:-It is the Boolean which will make changes in the dataframe if true.

python dropna Example:-

#importing panda’s module
Import pandas as pd
#making data frames from csv file
Data=pd.read_csv(“nba.csv”)
#making new dataframes with dropped Na values
New_data=data.dropna(axis=0,how=’any’)
#comparing sizes of dataframes
Print(“old data frame length:”,len(data),\nNew dataframe length:”, len(new_data), "\nNumber of rows with at least 1 NA value: ",
 (len(data)-len(new_data))))

Output: -

Old data frame length: 458
New data frame length: 364
Number of rows with at least 1 NA value: 94

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India