Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to drop NA?
I'm fairly familiar with python basics with regards to DataFrames and pandas. The problem I am encounter though is that I cannot properly drop NA values. The problem is I will have a simple DataFrame comprising of a 5x5 layout (for simplicity) and when the code drops the specific row, it removes the index value for that row as well. So rather than index [1,2,3,4,5], it will be index[1,3,4,5]. I have tried the index.reset function, which works, but when it reaches the end, it will look for the last index value + 1, which it doesn't have since the last row has been dropped. I cannot figure out how to properly remove NA values and keep a proper index. Here is a basic layout I have for testing purposes.

    for ea_rec in t_df.index:
        if pd.isnull(t_df['Name'][ea_rec]):
            t_df.dropna(t_df.index[ea_rec], inplace=True)
except KeyError:

I had to add the KeyError because it contains the one extra index value at the end after the entire DataFrame has been re-adjusted. Apologies if this sounds a bit confusing because I tried to find the best way to ask the question. Thanks.
This stack overflow question has some answers to that problem.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020