Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Read this CSV text with pd.read_csv:
x,y,z then the rows 1,2.0,a and 2,,b and ,3.0, and 4,5.0,d.
Find how many values are missing in each column, how many rows have at least one missing value, and how many rows are left after dropna().
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. isna().sum() counts per column. For the rows, isna().any(axis=1) is True for a row with a missing value.
Check. The second data row has no y. The third data row has no x and no z. So each column misses exactly one value, and two of the four rows have a missing value. After dropna, the 2 complete rows are left, with 3 columns.
Answer: {'x': 1, 'y': 1, 'z': 1}. Two rows have missing values, and dropna() leaves a table with the shape (2, 3).
Log in to join the discussion.
Loading…