Quantcast
Channel: How to drop rows of Pandas DataFrame whose value in a certain column is NaN - Stack Overflow
Browsing all 18 articles
Browse latest View live

Answer by cottontail for How to drop rows of Pandas DataFrame whose value in...

dropna vs boolean indexingIf we look at the source code, under the hood, dropna() is precisely notna()+ boolean indexing. Depending on what was passed to how=, all() or any() is called to reduce the...

View Article



Answer by rachwa for How to drop rows of Pandas DataFrame whose value in a...

You can also use notna inside query:In [4]: df.query('EPS.notna().values')Out[4]: STK_ID.1 EPS cashSTK_ID RPT_Date 600016 20111231 600016 4.3 NaN601939 20111231 601939 2.5 NaN

View Article

Answer by Simon for How to drop rows of Pandas DataFrame whose value in a...

you can try with:df['EPS'].dropna()

View Article

Answer by Taie for How to drop rows of Pandas DataFrame whose value in a...

The following method worked for me. It would help if none of the above methods work:df[df['colum_name'].str.len() >= 1]The basic idea is that you pick up the record only if the length strength is...

View Article

Image may be NSFW.
Clik here to view.

Answer by cs95 for How to drop rows of Pandas DataFrame whose value in a...

How to drop rows of Pandas DataFrame whose value in a certain column is NaNThis is an old question which has been beaten to death but I do believe there is some more useful information to be surfaced...

View Article


Answer by keramat for How to drop rows of Pandas DataFrame whose value in a...

Another version:df[~df['EPS'].isna()]

View Article

Answer by Pradeep Singh for How to drop rows of Pandas DataFrame whose value...

In datasets having large number of columns its even better to see how many columns contain null values and how many don't. print("No. of columns containing null...

View Article

Answer by Noordeen for How to drop rows of Pandas DataFrame whose value in a...

Simple and easy waydf.dropna(subset=['EPS'],inplace=True)source: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html

View Article


Answer by Gil Baggio for How to drop rows of Pandas DataFrame whose value in...

Simplest of all solutions:filtered_df = df[df['EPS'].notnull()]The above solution is way better than using np.isfinite()

View Article


Answer by Joe for How to drop rows of Pandas DataFrame whose value in a...

You can use this:df.dropna(subset=['EPS'], how='all', inplace=True)

View Article

Answer by MaxU - stand with Ukraine for How to drop rows of Pandas DataFrame...

yet another solution which uses the fact that np.nan != np.nan:In [149]: df.query("EPS == EPS")Out[149]: STK_ID EPS cashSTK_ID RPT_Date600016 20111231 600016 4.3 NaN601939 20111231 601939 2.5 NaN

View Article

Answer by David for How to drop rows of Pandas DataFrame whose value in a...

It may be added at that '&' can be used to add additional conditions e.g.df = df[(df.EPS > 2.0) & (df.EPS <4.0)]Notice that when evaluating the statements, pandas needs parenthesis.

View Article

Answer by Anton Protopopov for How to drop rows of Pandas DataFrame whose...

You could use dataframe method notnull or inverse of isnull, or numpy.isnan:In [332]: df[df.EPS.notnull()]Out[332]: STK_ID RPT_Date STK_ID.1 EPS cash2 600016 20111231 600016 4.3 NaN4 601939 20111231...

View Article


Answer by Kirk Hadley for How to drop rows of Pandas DataFrame whose value in...

I know this has already been answered, but just for the sake of a purely pandas solution to this specific question as opposed to the general description from Aman (which was wonderful) and in case...

View Article

Answer by Aman for How to drop rows of Pandas DataFrame whose value in a...

This question is already resolved, but... ...also consider the solution suggested by Wouter in his original comment. The ability to handle missing data, including dropna(), is built into pandas...

View Article


Answer by eumiro for How to drop rows of Pandas DataFrame whose value in a...

Don't drop, just take the rows where EPS is not NA:df = df[df['EPS'].notna()]

View Article

How to drop rows of Pandas DataFrame whose value in a certain column is NaN

I have this DataFrame and want only the records whose EPS column is not NaN: STK_ID EPS cashSTK_ID RPT_Date 601166 20111231 601166 NaN NaN600036 20111231 600036 NaN 12600016 20111231 600016 4.3...

View Article


Answer by Sole Galli for How to drop rows of Pandas DataFrame whose value in...

Those who want to make dropna part of a feature engineering / scikit-learn pipeline, can use DropMissingData from Feature-engine.The following will drop all rows with nan in a dataframe:import pandas...

View Article
Browsing all 18 articles
Browse latest View live




Latest Images