Pandas dropna with thresh: Drop only rows with too many NaN values

Pandas dropna with thresh: Drop only rows with too many NaN values

You can remove NaN from a Python Pandas data frame with dropna, but be careful: It removes rows with even one NaN, which can be overkill.

Pass “thresh” to allow some rows to remain, even if they contain NaN:

df.dropna(thresh=2)  # keeps rows with 2 or more non-NaN values