📅  最后修改于: 2023-12-03 15:31:27.140000             🧑  作者: Mango
isnull().mean()
is a function in Python that is used to find the percentage of missing values in a DataFrame. This function is available in the Pandas library.
The syntax of the isnull().mean()
function is as follows:
dataframe.isnull().mean()
Here, dataframe
is the name of the Pandas DataFrame that we want to analyze.
The isnull()
method returns a DataFrame consisting of boolean values that indicate whether each element of the original DataFrame is missing or not.
After that, the mean()
method is applied to calculate the mean of the boolean values across each column. This gives us the percentage of missing values in each column.
For example, if we have a Pandas DataFrame like this:
import pandas as pd
data = {'A': [1, 2, None, 4, None],
'B': [None, 6, 7, None, 9],
'C': [10, 11, 12, None, 14]}
df = pd.DataFrame(data)
The output of df
would be:
A B C
0 1.0 NaN 10.0
1 2.0 6.0 11.0
2 NaN 7.0 12.0
3 4.0 NaN NaN
4 NaN 9.0 14.0
Now, we can apply the isnull().mean()
function to find the percentage of missing values in each column:
percent_missing = df.isnull().mean()
print(percent_missing)
The output would be:
A 0.4
B 0.4
C 0.2
dtype: float64
This output tells us that column A and column B both have 40% missing values, while column C has 20% missing values.
In summary, isnull().mean()
is a useful function in Python that can help us analyze missing values in a Pandas DataFrame. By using this function, we can quickly find out the percentage of missing values in each column, which can help us identify potential issues with our data.