Created
August 27, 2020 23:30
-
-
Save jpiwowar/61ce0dd1751a3b71ef0219649db5d9d2 to your computer and use it in GitHub Desktop.
Print a "nicer" version of the pandas.DataFrame.shape output
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
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