Python | Pandas TimedeltaIndex.nbytes

TimedeltaIndex.nbytes Pandas TimedeltaIndex.nbytes returns the number of bytes occupied by the TimedeltaIndex object.

Syntax: TimedeltaIndex.nbytes

Return: size of the object in bytes

Example # 1: Use the TimedeltaIndex.nbytes attribute to find out the number of bytes used by the TimedeltaIndex object.

# import pandas as pd

import pandas as pd

 
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (start = ' 1 days 02: 00: 12.001124' , periods = 5 ,

freq = 'N' , name = 'Koala' )

  
# Print TimedeltaIndex

print (tidx)

Output:

Now we will print the number of bytes taken by the tidx object.

# find the size of the tidx object in b itah
tidx.nbytes

Output:

As we see on output, the TimedeltaIndex.nbytes attribute returned 40, which indicates that the tidx object is occupying this block of memory.

Example # 2: Use the attribute TimedeltaIndex.nbytes to find out the nanosecond value for each record of the TimedeltaIndex object.

# import pandas as pd

import pandas as pd

 
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (data < / code> = [ '-1 days 2 min 3us 10ns' , '1 days 06: 05: 01.000030' ,

'-1 days + 23: 59: 59.999999' ])

 
# Print TimedeltaIndex

print (tidx)

Output:

We will now print the number of bytes taken by the tidx object.

# find the size of the tidx object in bytes
tidx.nbytes

Output:

As we can see from the output, the TimedeltaIndex.nbytes attribute returned 24, indicating that the tidx object is occupying this block of memory.





Get Solution for free from DataCamp guru