Created
October 15, 2019 09:50
-
-
Save ohld/4e4bc1865fa6e7965fa936b88536ea09 to your computer and use it in GitHub Desktop.
Pandas DataFrame resume / summary for Data Analysis
This file contains hidden or 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
| def resumetable(df): | |
| print(f"Dataset Shape: {df.shape}") | |
| summary = pd.DataFrame(df.dtypes,columns=['dtypes']) | |
| summary = summary.reset_index() | |
| summary['Name'] = summary['index'] | |
| summary = summary[['Name','dtypes']] | |
| summary['Missing'] = df.isnull().sum().values | |
| summary['Uniques'] = df.nunique().values | |
| summary['First Value'] = df.loc[0].values | |
| summary['Second Value'] = df.loc[1].values | |
| summary['Third Value'] = df.loc[2].values | |
| for name in summary['Name'].value_counts().index: | |
| summary.loc[summary['Name'] == name, 'Entropy'] = round(stats.entropy(df[name].value_counts(normalize=True), base=2),2) | |
| return summary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment