Conversation

coding shouldnt be this hard, it's unreasonable. i asked ppl 'how many ppl have u had sex with', fill-in-the-blank and all i want to do is delete everything that isnt within a specific numerical range in the dataframe's column You'd think this would be pretty simple. you'd think.
84
344
Show replies
Replying to and
Try this: df.loc[~df['num_partners'].astype(str).isnumeric(), 'num_partners'] = np.nan # Assigns NaN to non numeric values df.loc[(df['num_partners'] < 10) | (df['num_partners'] > 20), 'num_partners'] = np.nan # Assigns Nan to the out of range numeric values
1
5
Show more replies