+

Python | Pandas DatetimeIndex.nanosecond

DatetimeIndex.nanosecond Pandas DatetimeIndex.nanosecond outputs an Index object containing the nanosecond values ​​present in each of the DatetimeIndex object records.

Syntax: DatetimeIndex.nanosecond

Return: Index containing nanosecond.

Example # 1: Use the DatetimeIndex.nanosecond attribute to find the nanosecond value present in a DatetimeIndex object.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here" N "represents nanoseconds

didx < / code> = pd.DatetimeIndex (start = `2014-08-01 10:05:45` , freq = `N` ,

  periods = 5 , tz = `Asia / Calcutta` )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to find all nanosecond values ​​present in DatetimeIndex object.

# find all nanosecond values ​​present in the object
didx.nanosecond

Output:

As we can see in the output, the function returned an Index object containing the nanosecond values ​​present in each record of the DatetimeIndex object.

Example # 2: Use the DatetimeIndex.nanosecond attribute to find the nanosecond value present in a DatetimeIndex object.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex

didx = pd.DatetimeIndex ([ `2014-08-01 10: 05: 45.000000010 + 05: 30` ,

`2014-08-01 10:05: 45.000000021 + 05:35` ])

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to find all nanosecond values ​​present in the DatetimeIndex object.

# find all nanosec Undefined values ​​present in the object
didx.nanosecond

Output:

As we can see in the output, the function returned an Index object containing the nanosecond values ​​present in each record of the DatetimeIndex object.

Get Solution for free from DataCamp guru