Last active
September 21, 2020 03:01
-
-
Save YiLi225/e21fe3662bf099f150bcf8c07c9bd839 to your computer and use it in GitHub Desktop.
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
## Convert Food_Category to the category-dtype and check backend codes ## | |
dairy_table['Food_Category'].astype('category').cat.codes | |
Out[97]: | |
index0 1 | |
index1 3 | |
index2 1 | |
index3 1 | |
index4 1 | |
...... | |
dtype: int8 | |
## Check the memory usage | |
object_mem = dairy_table['Food_Category'].memory_usage(index=False, deep=True) | |
category_mem = dairy_table['Food_Category'].astype('category').memory_usage(index=False, deep=True) | |
print(f'Total bytes for the object-dtype = {object_mem}\nTotal bytes for the category-dtype = {category_mem}') | |
Total bytes for the object-dtype = 1051 | |
Total bytes for the category-dtype = 427 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment