🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpandas

pandas Documentation

LOADING ENGINE...

df.notna()

AI & DATA SCIENCE // df-notna

df.notna() is the exact logical opposite of isna() — it returns a boolean DataFrame or Series marking True wherever a value is present (not missing).

Syntax

df.notna()

Deep Dive Course

notna(), aliased identically as notnull(), is functionally equivalent to negating the result of isna(), provided as a separate, readable method so code that specifically cares about present values doesn't need an extra negation to express that intent. It's commonly used with boolean indexing to select only the rows that do have a value in a specific column, the mirror image of using isna() to find the rows that don't.

1Understanding df.notna()

notna(), aliased identically as notnull(), is functionally equivalent to negating the result of isna(), provided as a separate, readable method so code that specifically cares about present values doesn't need an extra negation to express that intent. It's commonly used with boolean indexing to select only the rows that do have a value in a specific column, the mirror image of using isna() to find the rows that don't.

💡

df.notna() and negating df.isna() are exactly equivalent — use notna() directly whenever your logic is naturally phrased as selecting the values that are present, instead of an extra negation on isna().

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"email": ["a@x.com", np.nan, "c@x.com"]})
print(df["email"].notna())
localhost:3000

2Practical Example

Here is a real-world application of df.notna() showing how it is used in production Pandas code.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"name": ["Alice", "Bob", "Carol"], "email": ["a@x.com", np.nan, "c@x.com"]})
has_email = df[df["email"].notna()]
print(has_email)
localhost:3000

3Best Practices

Follow these guidelines when working with df.notna():

1. Use notna() directly when your logic is naturally about selecting present values, rather than writing an explicit negation of isna()

2. Combine notna() with boolean indexing to select only rows with a value in a specific required column

3. Use notna().sum() to count non-missing values per column, the mirror image of isna().sum() for counting missing ones

⚠️

Tip: df.notna() and negating df.isna() are exactly equivalent — use notna() directly whenever your logic is naturally phrased as selecting the values that are present, instead of an extra negation on isna().

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"email": ["a@x.com", np.nan, "c@x.com"]})
print(df["email"].notna())
localhost:3000

Examples

Example 01Basic Usage
import pandas as pd
import numpy as np

df = pd.DataFrame({"email": ["a@x.com", np.nan, "c@x.com"]})
print(df["email"].notna())
Example 02Advanced Example
import pandas as pd
import numpy as np

df = pd.DataFrame({"name": ["Alice", "Bob", "Carol"], "email": ["a@x.com", np.nan, "c@x.com"]})
has_email = df[df["email"].notna()]
print(has_email)

Best Practices

  • Use notna() directly when your logic is naturally about selecting present values, rather than writing an explicit negation of isna()
  • Combine notna() with boolean indexing to select only rows with a value in a specific required column
  • Use notna().sum() to count non-missing values per column, the mirror image of isna().sum() for counting missing ones

Interview Question

Is there any actual behavioral difference between df.notna() and manually negating the result of df.isna()?

Hint: Think about whether notna() does anything isna() plus a negation couldn't already do.

No, there's no behavioral difference at all — notna() is implemented as exactly the logical negation of isna(), so notna() and manually negating isna()'s result always produce identical results for any input. notna() exists purely for readability, so code that's naturally about identifying present values doesn't need to express that as a double negative, not missing, when it can just say directly what it means.

Exercises

MediumPractice using df.notna() in a real scenario.
View Solution
import pandas as pd
import numpy as np

df = pd.DataFrame({"email": ["a@x.com", np.nan, "c@x.com"]})
print(df["email"].notna())

Frequently Asked Questions

Is there any actual behavioral difference between df.notna() and manually negating the result of df.isna()?

No, there's no behavioral difference at all — notna() is implemented as exactly the logical negation of isna(), so notna() and manually negating isna()'s result always produce identical results for any input. notna() exists purely for readability, so code that's naturally about identifying present values doesn't need to express that as a double negative, not missing, when it can just say directly what it means.

Related Functions

df-isnaboolean-indexingdf-dropna