Skip to content

Instantly share code, notes, and snippets.

@jpiwowar
Created August 27, 2020 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpiwowar/61ce0dd1751a3b71ef0219649db5d9d2 to your computer and use it in GitHub Desktop.
Save jpiwowar/61ce0dd1751a3b71ef0219649db5d9d2 to your computer and use it in GitHub Desktop.
Print a "nicer" version of the pandas.DataFrame.shape output
def pretty_shape(my_df,desc):
'''
Displays the shape of a pandas dataframe in a prettier format.
I don't know why the default display bugs me. It just does.
my_df: source dataframe
desc: Descriptive text. Go nuts.
'''
print(f'\n{desc}:')
display(pd.DataFrame(my_df.shape,
columns=['count'])\
.rename(index={0:"rows",1:"cols"})\
.T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment