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?
CodePudding user response:
df[df['Salary'].isnull()].shape[0]
CodePudding user response:
you can try this :
df['Salary'].isnull().sum()
if you wanna count the number of Nan in each column , simply :
df.isnull().sum()