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.
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.
try: 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) t_df.reset_index(inplace=True) except KeyError: pass
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.