+

Python | Series Pand.hasnans

Pandas Series — it is a one-dimensional array with axis labels. Tags do not have to be unique, but must be hashable. The object supports indexing based on integers and labels and provides many methods for performing index-related operations.

Series.hasnans Pandas Series.hasnans returns a boolean value. It returns True if the given Series object has no values, otherwise it returns False .

Syntax: Series .hasnans

Parameter: None

Returns: boolean

Example # 1: Use the Series.hasnans attribute to check if this Series object has any missing values.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ `New York` , `Chicago` , `Toronto` , ` Lisbon` ])

 
# Create row axis labels

sr.index = [ ` City 1` , `City 2` , `City 3` , ` City 4`

 
# Print series

print (sr)

Output:

Now we will use the < code> Series.hasnans to check for missing values ​​in the sr object.

# check for missing values.
sr.hasnans

Output:


As we can see from the output, the Series attribute .hasnans returned False indicating there are no missing values ​​for this series object.

Example # 2: Use the attribute Series.hasnans to check if the given Series has any missing values.

Output:

We will now use the Series.hasnans attribute to check for missing values ​​in the sr object.

# import pandas as pd

import pandas as pd

 
# Create a series

sr = pd.Series ([ 1000 , `Calgarry` , 5000 , None ])

  
# Print series

print (sr)

# check for missing values.
sr.hasnans

Output:

As we can see from the output, the Series.hasnans attribute returned True indicating that this series object has at least one missing value.

Get Solution for free from DataCamp guru