Get Details about the Dataset
We can use the describe() method which returns a table containing details about the dataset. The count property directly gives the count of non-NaN values in each column. So, we can get the count of NaN values, if we know the total number of observations.
Python3
import pandas as pd import numpy as np # dictionary of lists dict = { 'A' :[ 1 , 4 , 6 , 9 ], 'B' :[np.NaN, 5 , 8 , np.NaN], 'C' :[ 7 , 3 , np.NaN, 2 ], 'D' :[ 1 , np.NaN, np.NaN, np.NaN] } # creating dataframe from the # dictionary data = pd.DataFrame( dict ) data.describe() |
Output:
RECOMMENDED ARTICLES – How to Drop Rows with NaN Values in Pandas DataFrame
How to count the number of NaN values in Pandas?
We might need to count the number of NaN values for each feature in the dataset so that we can decide how to deal with it. For example, if the number of missing values is quite low, then we may choose to drop those observations; or there might be a column where a lot of entries are missing, so we can decide whether to include that variable at all using Python in Pandas
Contact Us