'Pandas dataframe- Count rows where specific column is NaN

I need to count the number of rows of a dataframe where the column Salary is Nan?

I tried this approach

print(df.count(df[df['Salary'].isnull()]))

but I got the following error

Traceback (most recent call last):
  File "C:\Users\fdpires\Desktop\MEI\DESCO\ex2.py", line 69, in <module>
    print(df.count(df[df['Salary'].isnull()]))
  File "C:\Users\fdpires\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 9846, in count
    axis = self._get_axis_number(axis)
  File "C:\Users\fdpires\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 550, in _get_axis_number
    return cls._AXIS_TO_AXIS_NUMBER[axis]
TypeError: unhashable type: 'DataFrame'

How can I solve my problem?



Solution 1:[1]

df[df['Salary'].isnull()].shape[0]

Solution 2:[2]

you can try this :

df['Salary'].isnull().sum()

if you wanna count the number of Nan in each column , simply :

df.isnull().sum()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moun
Solution 2