Count NaN Values in pandas DataFrame in Python (Examples) | is.na & sum Functions | By Row & Column



Count NaN Values in pandas DataFrame in Python (Examples) | is.na & sum Functions | By Row & Column

Count NaN Values in pandas DataFrame in Python (Examples) | is.na & sum Functions | By Row & Column

How to get the number of NaN values in a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/count-nan-values-in-pandas-dataframe-python
Python code of this video:

import pandas as pd # Import pandas library to Python

data = pd.DataFrame({‘x1’:[1, float(‘NaN’), 2, 3, float(‘NaN’), 4], # Create example DataFrame
‘x2’:[9, float(‘NaN’), 9, 9, 9, 9],
‘x3’:range(1, 7)})
print(data) # Print example DataFrame

print(data.isna().sum()) # Number of NaNs by column
# x1 2
# x2 1
# x3 0
# dtype: int64

print(data[‘x1’].isna().sum()) # Number of NaNs in one column
# 2

print(data.isnull().sum(axis = 1)) # Number of NaNs by row
# 0 0
# 1 2
# 2 0
# 3 0
# 4 1
# 5 0
# dtype: int64

print(data.loc[[4]].isna().sum().sum()) # Number of NaNs in one row
# 1

print(data.isna().sum().sum()) # Number of NaNs in entire DataFrame
# 3

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn – Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork

Music by bensound.com

Comments are closed.