Pandas Series: isna() function
Detect missing values in the given Pandas series
The isna() function is used to detect missing values.
Syntax:
Series.isna(self)
Returns: Series- Mask of bool values for each element in Series that indicates whether an element is not an NA value.
Example - Show which entries in a DataFrame are NA:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame({'age': [6, 7, np.NaN],
'born': [pd.NaT, pd.Timestamp('1998-04-25'),
pd.Timestamp('1940-05-27')],
'name': ['Alfred', 'Spiderman', ''],
'toy': [None, 'Spidertoy', 'Joker']})
df
Output:
age born name toy 0 6.0 NaT Alfred None 1 7.0 1998-04-25 Spiderman Spidertoy 2 NaN 1940-05-27 Joker
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame({'age': [6, 7, np.NaN],
'born': [pd.NaT, pd.Timestamp('1998-04-25'),
pd.Timestamp('1940-05-27')],
'name': ['Alfred', 'Spiderman', ''],
'toy': [None, 'Spidertoy', 'Joker']})
df.isna()
Output:
age born name toy 0 False True False True 1 False False False False 2 True False False False
Example - Show which entries in a Series are NA:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([6, 7, np.NaN])
s
Output:
0 6.0 1 7.0 2 NaN dtype: float64
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([6, 7, np.NaN])
s.isna()
Output:
0 False 1 False 2 True dtype: bool
Previous: Subset rows or columns of Pandas dataframe
Next: Detect existing values in Pandas series
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/series/series-isna.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics