Course Content
Pandas First Steps
Pandas First Steps
Finding Null Values
Dataframes often contain missing values, represented as None
or np.NaN
. When working with dataframes, it's essential to identify these missing values. For this purpose, pandas offers specific methods.
The first of these is isna()
, which returns a boolean dataframe. In this context, a True value indicates a missing value within the dataframe, while a False value suggests the value is present.
For clarity, let's review an example. Run the code provided to see a dataframe filled with True and False values, offering a clearer understanding.
import pandas as pd import numpy as np dataset = {'animal': [np.NaN, 'Dog', np.NaN, 'Cat','Parrot', None], 'name': ['Dolly', None, 'Erin', 'Kelly', None, 'Odie']} animal = pd.DataFrame(dataset) # Find missing values missing_value = animal.isna() print(missing_value)
The second method is isnull()
. It behaves identically to the previous one, with no discernible difference between them. Let's examine its application. Running the accompanying code will show if the resulting DataFrame matches the one from the prior example.
import pandas as pd import numpy as np dataset = {'animal': [np.NaN, 'Dog', np.NaN, 'Cat','Parrot', None], 'name': ['Dolly', None, 'Erin', 'Kelly', None, 'Odie']} animal = pd.DataFrame(dataset) # Find missing values missing_value = animal.isnull() print(missing_value)
Swipe to show code editor
Your objective is to pinpoint the missing values in a given dataframe named data_frame
.
Thanks for your feedback!
Finding Null Values
Dataframes often contain missing values, represented as None
or np.NaN
. When working with dataframes, it's essential to identify these missing values. For this purpose, pandas offers specific methods.
The first of these is isna()
, which returns a boolean dataframe. In this context, a True value indicates a missing value within the dataframe, while a False value suggests the value is present.
For clarity, let's review an example. Run the code provided to see a dataframe filled with True and False values, offering a clearer understanding.
import pandas as pd import numpy as np dataset = {'animal': [np.NaN, 'Dog', np.NaN, 'Cat','Parrot', None], 'name': ['Dolly', None, 'Erin', 'Kelly', None, 'Odie']} animal = pd.DataFrame(dataset) # Find missing values missing_value = animal.isna() print(missing_value)
The second method is isnull()
. It behaves identically to the previous one, with no discernible difference between them. Let's examine its application. Running the accompanying code will show if the resulting DataFrame matches the one from the prior example.
import pandas as pd import numpy as np dataset = {'animal': [np.NaN, 'Dog', np.NaN, 'Cat','Parrot', None], 'name': ['Dolly', None, 'Erin', 'Kelly', None, 'Odie']} animal = pd.DataFrame(dataset) # Find missing values missing_value = animal.isnull() print(missing_value)
Swipe to show code editor
Your objective is to pinpoint the missing values in a given dataframe named data_frame
.
Thanks for your feedback!