You have NaN values in a column and you want to count how many of them are?
Let’s read a dataset to work with.
import pandas as pd url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/fruit_prices.csv' df = pd.read_csv(url) df.head()
We can see that in this dataframe we have some NaN values in each columns. To count the number of NaN values in each columns, we can use the df.isnull().sum().
df.isnull() tells you whether a cell contains a Null value or Not.
True means a cell contains a NaN or Null value. Then we use .sum() to count how many of the cells in each columns contains Null values.