Skip to content

Instantly share code, notes, and snippets.

@jaganadhg
Created September 3, 2015 18:30
Show Gist options
  • Save jaganadhg/e9d91c4750226eac6eb9 to your computer and use it in GitHub Desktop.
Save jaganadhg/e9d91c4750226eac6eb9 to your computer and use it in GitHub Desktop.
Missing Value Ratio with Pandas
from __future__ import division
import pandas as pd
def missing_value_ratio(pd_series):
"""
:param pd_series: a Pandas Series object
:return ratio: float ; missing value ratio
Find the missing value ratio.
missing value ratio = no of missing value / total number of rows
no of missing value is the count of np.NaN in a Pandas Series
"""
return pd_series.isnull().sum() / pd_series.count()
if __name__ == "__main__":
data = pd.read_csv("airquality.csv")
for column in data.columns:
print col,"\t",missing_value_ratio(data[column])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment