Thursday, July 4, 2024
HomeLanguagesPythonPython | Pandas Index.nbytes

Python | Pandas Index.nbytes

Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects.

Pandas Index.nbytes attribute return the number of bytes required to store the underlying data of the given Index object.

Syntax: Index.nbytes

Parameter : None

Returns : number of bytes needed to store the data

Example #1: Use Index.nbytes attribute to find out the number of bytes required to store the underlying data of the given Index object.




# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(['Melbourne', 'Sanghai', 'Lisbon', 'Doha', 'Moscow', 'Rio'])
  
# Print the index
print(idx)


Output :

Now we will use Index.nbytes attribute to find out the number of bytes required to store the data in the given Index object.




# return the number of bytes occupied 
# by idx object
result = idx.nbytes
  
# Print the result
print(result)


Output :

As we can see in the output, the Index.nbytes attribute has returned 48, indicating that 48 bytes are needed to store the data in the given Index object.
 
Example #2 : Use Index.nbytes attribute to find out the number of bytes required to store the underlying data of the given Index object.




# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index([900 + 3j, 700 + 25j, 620 + 10j, 388 + 44j, 900])
  
# Print the index
print(idx)


Output :

Now we will use Index.nbytes attribute to find out the number of bytes required to store the data in the given Index object.




# return the number of bytes occupied 
# by idx object
result = idx.nbytes
  
# Print the result
print(result)


Output :

As we can see in the output, the Index.nbytes attribute has returned 40, indicating that 40 bytes are needed to store the data in the given Index object.

Thapelo Manthata
I’m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments