Skip to content

Instantly share code, notes, and snippets.

@avikaco
Created December 14, 2018 13:47
Show Gist options
  • Select an option

  • Save avikaco/f58a9e3ce489474fdfb88b9ed2ba6e1d to your computer and use it in GitHub Desktop.

Select an option

Save avikaco/f58a9e3ce489474fdfb88b9ed2ba6e1d to your computer and use it in GitHub Desktop.
Get dataframe more information
# ... 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