C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Pandas DataFrame.dropna()If your dataset consists of null values, we can use the dropna() function to analyze and drop the rows/columns in the dataset. Syntax:
 DataFrameName.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False) Parameters:
 
 Returns
 It returns the DataFrame from which NA entries has been dropped. For Demonstration, first, we are taking a csv file that will drop any column from the dataset. 
import pandas as pd
aa = pd.read_csv("aa.csv")
aa.head()
Output 
 Code:
# importing pandas module 
import pandas as pd  
# making data frame from csv file 
info = pd.read_csv("aa.csv")   
# making a copy of old data frame 
copy = pd.read_csv("aa.csv") 
  
# creating value with all null values in new data frame 
copy["Null Column"]= None
  
# checking if column is inserted properly  
print(info.columns.values, "\n", copy.columns.values) 
  
# comparing values before dropping null column 
print("\nColumn number before dropping Null column\n", 
       len(info.dtypes), len(copy.dtypes)) 
  
# dropping column with all null values 
copy.dropna(axis = 1, how ='all', inplace = True) 
  
# comparing values after dropping null column 
print("\nColumn number after dropping Null column\n", 
      len(info.dtypes), len(info.dtypes))  
Output [' Name Hire Date Salary Leaves Remaining'] [' Name Hire Date Salary Leaves Remaining' 'Null Column'] Column number before dropping Null column 1 2 Column number after dropping Null column 1 1 The above code dropped the null column from the dataset and returned a new DataFrame. 
Next TopicDataFrame.fillna()
 
 |