+

Python | Pandas TimedeltaIndex.hasnans

TimedeltaIndex.hasnans Pandas TimedeltaIndex.hasnans returns a boolean value. It returns True if the Timedeltaindex object contains any NaN values ​​otherwise it returns False indicating that there are no NaN values ​​.

Syntax: TimedeltaIndex.hasnans

Return: boolean

Example # 1: Use the TimedeltaIndex.hasnans attribute to check if any NaN value is present in the given TimedeltaIndex.

# import pandas as pd

import pandas as pd

  
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (data = [ `1 days 02: 00: 00` , ` 1 days 06: 05: 01.000030` , None ])

 
# Print TimedeltaIndex

print (tidx)

Output:

Now we check if any NaN value is present in the given TimedeltaIndex.

# check for missing values ​​
tidx.hasnans

Exit d:

As we can see from the output, the TimedeltaIndex.hasnans returned True indicating that the object has a NaN value.

Example # 2: Use the TimedeltaIndex.hasnans to check if any NaN value is present in the given TimedeltaIndex.

# import pandas as pd

import pandas as pd

 
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (data = [ `-1 days 2 min 3us` , ` 1 days 06: 05: 01.000030`

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

 
# Print TimedeltaIndex

print (tidx)

Output:

Now we check if any NaN value is present in the given TimedeltaIndex.

# check for missing values ​​
tidx.hasnans

  Output:

As we can see in the output, the TimedeltaIndex attribute. hasnans returned False indicating that there is no NaN value in the object.

Get Solution for free from DataCamp guru