0
0
Pandasdata~5 mins

Dropping missing values with dropna() in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the dropna() function do in pandas?

The dropna() function removes rows or columns that contain missing values (NaN) from a DataFrame or Series.

Click to reveal answer
beginner
How do you drop rows with any missing values in a DataFrame named df?

Use df.dropna(). This removes all rows that have at least one missing value.

Click to reveal answer
beginner
What parameter do you use with dropna() to drop columns instead of rows?

Use axis=1 to drop columns with missing values, like df.dropna(axis=1).

Click to reveal answer
intermediate
How can you drop rows only if all values are missing?

Use how='all' in dropna(), like df.dropna(how='all'). This keeps rows with at least one value.

Click to reveal answer
intermediate
What does the thresh parameter do in dropna()?

thresh sets the minimum number of non-missing values required to keep a row or column. For example, df.dropna(thresh=2) keeps rows with at least 2 non-NaN values.

Click to reveal answer
What is the default behavior of df.dropna()?
ADrops columns only if all values are missing
BDrops rows with any missing values
CDrops rows only if all values are missing
DDrops columns with any missing values
How do you drop columns with missing values using dropna()?
AUse <code>axis=1</code>
BUse <code>axis=0</code>
CUse <code>how='all'</code>
DUse <code>thresh=1</code>
Which parameter keeps rows that have at least one non-missing value?
A<code>how='all'</code>
B<code>how='any'</code>
C<code>thresh=0</code>
D<code>axis=1</code>
What does df.dropna(thresh=3) do?
ADrops columns with fewer than 3 missing values
BDrops rows with more than 3 missing values
CDrops columns with exactly 3 missing values
DDrops rows with fewer than 3 non-missing values
If you want to remove rows only when all columns are missing, which dropna() call is correct?
A<code>df.dropna(how='any')</code>
B<code>df.dropna(axis=1)</code>
C<code>df.dropna(how='all')</code>
D<code>df.dropna(thresh=1)</code>
Explain how you would use dropna() to clean a dataset by removing rows with missing data. Include how to keep rows with at least some data.
Think about when to drop rows and when to keep them based on missing data.
You got /4 concepts.
    Describe the role of the thresh parameter in dropna() and give an example of its use.
    It controls how strict the dropping is based on data completeness.
    You got /3 concepts.