The isna()
function in Pandas is used to check for null or missing values in a DataFrame or Series.
This function returns a boolean value for each element in the DataFrame or Series, indicating whether the element is null or missing.
Here's an example of using the isna()
function in Pandas to check for null values:
import pandas as pd
# create a sample DataFrame
df = pd.DataFrame({"A": [1, 2, 3, 4, 5],
"B": [None, 7, 8, 9, 10]})
# check for null values in the DataFrame
df_isna = df.isna()
# display the result
print(df_isna)
This will check for null values in the DataFrame, and return a new DataFrame with a boolean value for each element indicating whether the element is null or not.
The output will be:
A B
0 False True
1 False False
2 False False
3 False False
4 False False
You can also use the isna()
function to check for missing values in a series.
For example:
# create a sample series
s = pd.Series([1, 2, None, 4, 5])
# check for missing values in the series
s_isna = s.isna()
# display the result
print(s_isna)
This will check for missing values in the series, and return a new series with a boolean value for each element indicating whether the element is missing or not.
The output will be:
0 False
1 False
2 True
3 False
4 False
dtype: bool
The isna()
function is useful for checking for null or missing values in a dataframe or series, and it returns a boolean value for each element indicating whether the element is null or missing.
Related tutorials curated for you
How to sort a series in Pandas
How to create a bar chart in Pandas
How to get the number of columns in a Pandas DataFrame
How to find the mode in a Pandas DataFrame
How to change the order of columns in Pandas
What is nlargest() in Pandas?
How to reshape a Pandas DataFrame
How to drop an index column in Pandas
How to use ffill() in Pandas
How to write a Pandas DataFrame to SQL
How to give multiple conditions in loc() in Pandas
How to split a Pandas DataFrame by a column value