-1

I just want to count all NA values grouped by the first index, name_of_collection. And print the each collection name corresponding to their number of NA values. Could anybody help me? Thank you so much!! The expected output:

name_of_collection # of NA
autoglyphs_Data_Clean 48 (for example)
veefriends_Data_Clean 57 (for example)

dataset:

Barmar
  • 741,623
  • 53
  • 500
  • 612
miaa
  • 11
  • 3
  • Please share some sample data *as text, not as image*, ideally following the instructions on [How to make good reproducible pandas examples](https://stackoverflow.com/a/20159305/15873043). – fsimonjetz Sep 14 '22 at 15:36
  • Please try and paste a sample dataset as text. That way, people can copy-paste your data and help you faster. – Mortz Sep 14 '22 at 15:36

1 Answers1

0

Let "col" be the name of the column where you're looking for the NA values and df your dataframe. Then this should work :

df["is_na"] = df["col"].isna()
df.groupby("name_of_collection")["is_na"]
.sum()
.reset_index()
.rename(columns={"is_na":"# of NA"})
Scaro974
  • 199
  • 5