Python | Pandas Index.memory_usage()
Last Updated :
07 Oct, 2021
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Index.memory_usage() function return the memory usage of the Index. It returns the sum of the memory used by all the individual labels present in the Index.f
Syntax: Index.memory_usage(deep=False)
Parameters :
deep : Introspect the data deeply, interrogate object dtypes for system-level memory consumption
Returns : bytes used
Example #1: Use Index.memory_usage() function to find the overall memory used by the Index object.
Python3
import pandas as pd
idx = pd.Index([ 'Labrador' , 'Beagle' , 'Mastiff' , 'Lhasa' , 'Husky' , 'Beagle' ])
idx
|
Output :
Now we will use Index.memory_usage() function to find the memory usage of the idx object.
Output :
The function has returned the value of 48 indicating that 48 bytes of memory are being used.
Example #2: Use Index.memory_usage() function to check the memory usage of the MultiIndex object.
Python3
import pandas as pd
midx = pd.MultiIndex.from_arrays([[ 'Mon' , 'Tue' , 'Wed' , 'Thr' ], [ 10 , 20 , 30 , 40 ]],
names = ( 'Days' , 'Target' ))
midx
|
Output :
Now we will check the amount of memory used by the midx object.
Output :
As we can see in the output, the function has returned 180 indicating that the midx object is using 180 bytes of memory.
Share your thoughts in the comments
Please Login to comment...