Tunk
Tunk

Reputation: 151

Delete DataFrame Columns Based on Row Value

Given a Pandas DataFrame, I'm trying to delete columns that contain any row values greater than or equal to 109 and row values less than or equal to 10-9.

What would be the best method to perform such an action?

Note: I have NaN types in the DataFrame, which I would like to keep, i.e. the code has to work with NaN types.

Upvotes: 1

Views: 179

Answers (1)

EFT
EFT

Reputation: 2369

If you really must keep those values NaN, you could first fill them in with a placeholder, then remove the placeholder after filtering.

df.fillna('None placeholder', inplace=True)
df = df[(df > 10**(-9)) & (df < 10**9)].dropna(axis=1)
df.replace('None placeholder', np.nan, inplace=True)

Upvotes: 1

Related Questions