justmarkham / pycon-2018-tutorial

Using pandas for Better (and Worse) Data Science

Home Page:https://www.dataschool.io/best-practices-with-pandas/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

replacing stop duration where "1" or "2"

pirsquared opened this issue · comments

A very pandas-esque way to replace the "1" or "2" with np.nan is to use the pandas.Series.mask method.

ri.stop_duration.mask(ri.stop_duration.isin(['1', '2']), inplace=True)
ri.stop_duration.value_counts(dropna=False)

0-15 Min     69543
16-30 Min    13635
NaN           5335
30+ Min       3228
Name: stop_duration, dtype: int64

@pirsquared Neat! Thanks for sharing!