Last active
March 12, 2023 18:50
-
-
Save edvardm/485241adda07fb7da54dddfc9e8111e6 to your computer and use it in GitHub Desktop.
more informative describe()
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
# Credits to answer in https://stackoverflow.com/questions/53173927/pandas-extensive-describe-include-count-the-null-values | |
def stats(df: pd.DataFrame) -> pd.DataFrame: | |
"""Like describe() but return dataframe, with datatypes and ratio of NaN values""" | |
st = df.describe() | |
total_n = len(df) | |
st.loc["dtype"] = df.dtypes | |
st.loc["n"] = total_n | |
st.loc["nan_n"] = total_n - df.count() # number of NaNs | |
st.loc["nan_r"] = df.isnull().mean() # ratio NaN/total length | |
return st |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment