I am using dropna to get rid of the NaN values, but instead of just dropping them i want to get a new table where those rows are saved. That's to say from the current code:
df_weight.dropna(subset = ["age"], inplace=True)
df_weight.dropna(subset = ["height"], inplace=True)
df_weight.dropna(subset = ["weight"], inplace=True)
df_weight
i want to save the rows that are droppen in the line df_weight.dropna(subset = ["weight"], inplace=True)
. I think that dropna does not have a return value, so there is any work around to archive this?
CodePudding user response:
you can try as follows. if you share the DF, it will be easier to reproduce and provide the working solution
its an idea or direction
df_weight.isna()['age']
df_weight.isna()['height']
df_weight.isna()['weight']
CodePudding user response:
You could use
dropped_rows_df = df_weight[df_weight.isna(axis=0, how='any', subset=['age','height','weight'])]