Created
December 14, 2018 13:47
-
-
Save avikaco/f58a9e3ce489474fdfb88b9ed2ba6e1d to your computer and use it in GitHub Desktop.
Get dataframe more information
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
| # ... your Python code | |
| def getDataframeInfo(df): | |
| dfInfo = pd.DataFrame(data={'DataFeatures':list(df)}) | |
| dfInfo['DataType'] = dfInfo['DataFeatures'].apply(lambda col: df.dtypes[col]) | |
| dfInfo['Null'] = dfInfo['DataFeatures'].apply(lambda col: df[col].isnull().sum(axis='index')) | |
| dfInfo['NullPercentage'] = dfInfo['Null'].apply(lambda nullCount: nullCount / df.shape[0]) | |
| dfInfo['Unique'] = dfInfo['DataFeatures'].apply(lambda col: df[col].nunique()) | |
| dfInfo['UniqueSample'] = dfInfo['DataFeatures'].apply(lambda col: df[col].unique()[0:5]) | |
| return dfInfo | |
| getDataframeInfo(YOUR_DATAFRAME_VARIABLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment