Skip to content
Fix Code Error

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

March 13, 2021 by Code Error
Posted By: Anonymous

I have this DataFrame and want only the records whose EPS column is not NaN:

>>> df
                 STK_ID  EPS  cash
STK_ID RPT_Date                   
601166 20111231  601166  NaN   NaN
600036 20111231  600036  NaN    12
600016 20111231  600016  4.3   NaN
601009 20111231  601009  NaN   NaN
601939 20111231  601939  2.5   NaN
000001 20111231  000001  NaN   NaN

…i.e. something like df.drop(....) to get this resulting dataframe:

                  STK_ID  EPS  cash
STK_ID RPT_Date                   
600016 20111231  600016  4.3   NaN
601939 20111231  601939  2.5   NaN

How do I do that?

Solution

Don’t drop, just take the rows where EPS is not NA:

df = df[df['EPS'].notna()]
Answered By: Anonymous

Related Articles

  • How to modify pre_close in batches
  • How to convert daily data into weekly data in batches
  • Is it possible to move each row to end of same row…
  • Dataframe to pivot using pandas
  • Change column type in pandas
  • Vuejs function with multiple data
  • How to get the last N rows of a pandas DataFrame?
  • MySQL GROUP BY two columns
  • Pandas Merging 101
  • Form field border-radius is not working only on the…
  • Pandas - Reshape a dataframe columns based on…
  • How to return a list from a pos tag column?
  • Pandas - fill a column with value from another…
  • Filter dataframe rows if value in column is in a set…
  • Pandas pivot_table: filter on aggregate function
  • Access PostgreSQL hstore keys and values in Python…
  • Importing Pandas gives error AttributeError: module…
  • How to find which columns contain any NaN value in…
  • Create a day-of-week column in a Pandas dataframe…
  • Pandas multi-index unstack to single row
  • "Large data" workflows using pandas
  • Remove value from localStorage in Vuejs
  • How to drop a list of rows from Pandas dataframe?
  • Use Set() in MobX with TypeScript?
  • How to join dataframe?
  • Merge 2 dataframes of different sizes after a…
  • How do I expand the output display to see more…
  • Numpy isnan() fails on an array of floats (from…
  • pandas: best way to select all columns whose names…
  • Python pandas: fill a dataframe row by row
  • How to Insert cell reference in VBA code for…
  • use mysql SUM() in a WHERE clause
  • Convert pandas.Series from dtype object to float,…
  • MySQL - sum column value(s) based on row from the same table
  • Is this request generated by EF Core buggy or is it my code?
  • how to split dataframe cells using delimiter into…
  • Python Pandas - Time Series Find Index of Previous Row
  • Pandas read_csv low_memory and dtype options
  • Pick last valid data dates from pair columns in a…
  • How do I split out a multi-index dataframe with a…
  • What's the proper way to set a parent property in Backbone?
  • Replacing Pandas or Numpy Nan with a None to use…
  • Merge two dataframes by index
  • Dataframe count set of conditions passed by several…
  • How do I divide values across dataframes in pandas?
  • How do I remove 'Nan' values while reading a PDF…
  • How to fix Python Numpy/Pandas installation?
  • Calculate count of a numeric column into new columns…
  • Pandas Multi Index column names
  • pandas: merge (join) two data frames on multiple columns
  • How to deal with SettingWithCopyWarning in Pandas
  • Pandas - DF with lists - find all rows that match a…
  • Assigning columns to a hierarchical higher Multiindex level
  • Set value for particular cell in pandas DataFrame…
  • How to append rows in a pandas dataframe in a for loop?
  • Get total of Pandas column
  • SQL query return data from multiple tables
  • Concatenate rows of two dataframes in pandas
  • Python pandas Filtering out nan from a data…
  • How to add multiple columns to pandas dataframe in…
  • How to replace NaN values by Zeroes in a column of a…
  • Pandas counting/adding values by date and id
  • How to Incrementally Increase from a Starting Value…
  • How to join two different line plots on a single…
  • Pandas: tidy multilevel data
  • Merge list of results into a single variable with Python
  • Creating a dataframe of two loops using haversine…
  • Manual Calculation of tanh in Tensorflow Keras Model…
  • Pandas - Get first row value of a given column
  • Splitting dataframe into multiple dataframes
  • find duplicateds and fill column
  • Python script to delete duplicates in csv file…
  • Pandas dataframe avoid looping through columns and rows
  • Numbering rows in pandas dataframe (with condition)
  • Python - Delete lines from dataframe (pandas)
  • Pandas: How to remove numbers and special characters…
  • pandas read_csv index_col=None not working with…
  • How to compare two double values in Java?
  • Counting values with condition in one DataFrame and…
  • How to create a groupby of two columns with all…
  • How to combine the data from two different…
  • How to properly apply a lambda function into a…
  • Find row where values for column is maximal in a…
  • pandas resample documentation
  • Pandas: Get Grouped and Conditioned Last Value
  • Fill values within dates according other DataFrame
  • How to save a pandas DataFrame table as a png
  • Binning column with python pandas
  • How to convert array column to int array in Pandas?
  • Display rows with one or more NaN values in pandas dataframe
  • Calculate repeat purchase probability
  • Pandas column concatenation
  • Match everything that's not a digit or white space…
  • Improve INSERT-per-second performance of SQLite
  • How to group two items with two dates and get…
  • Output data from all columns in a dataframe in pandas
  • python pandas extract year from datetime: df['year']…
  • How are iloc and loc different?
  • Creating an empty Pandas DataFrame, then filling it?
  • Pandas conditional counting by date

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to trigger a file download when clicking an HTML button or JavaScript

Next Post:

What is the difference between String and string in C#?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error