Created
September 3, 2015 18:30
-
-
Save jaganadhg/e9d91c4750226eac6eb9 to your computer and use it in GitHub Desktop.
Missing Value Ratio with Pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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