How can I drop rows from a Pandas DataFrame where a specific column has missing values (NaN)?

I have a Pandas dataframe where some rows have missing values (NaN) in a certain column. I want to drop all the rows where the value in that column is NaN. How can I do this?

Here’s an example of my dataframe:

This is the output of this code:


   A    B
0  1  foo
1  2  bar
2  3  None
3  4  baz

As you can see, the value in column B of row 2 is None (which is equivalent to NaN). I want to drop that row.

Here’s the code I’ve tried so far:

df.dropna(subset=['A'], inplace=True)
print(df)

However, this doesn’t seem to work. Can anyone help me figure out what I’m doing wrong here? And are there any alternative ways to drop rows with NaN values in a certain column? Thanks for any help you can provide.