Use groupby to count missing values in different groups

data:
insert image description here

Requirement: We want to count the number of missing values ​​of different groups (A, B) in column a.
Implementation: First extract the missing values ​​of different columns, and then use groupby for statistical calculation

pd.DataFrame(df[x].isnull().groupby(df['a']).sum() for x in df.columns[1:]).T.reset_index()

insert image description here

Reference source: Pandas count null values ​​in a groupby function

Guess you like

Origin blog.csdn.net/weixin_46599926/article/details/127932208