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?
EDIT: my db comes from https://data.world/bgadoci/crossfit-data/workspace/file?filename=athletes.csv . I deleted all the other rows to make a mini db: after loading the data into pandas i do df_weight = df[['gender','age','height','weight']]
with the code mentioned above i get something like this (where the desired row datatype is marked)
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']
You could use
dropped_rows_df = df_weight[df_weight[['age','height','weight']]].isna().any(axis=1)]
#then
df_weight.dropna(subset = ["age"], inplace=True)
df_weight.dropna(subset = ["height"], inplace=True)
df_weight.dropna(subset = ["weight"], inplace=True)
df_weight
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.