Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active September 13, 2020 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/29b966323f030d5efc0ee6fb6a6d660a to your computer and use it in GitHub Desktop.
Save YiLi225/29b966323f030d5efc0ee6fb6a6d660a to your computer and use it in GitHub Desktop.
## where() to replace values
food_names_list = ["Cows' milk, whole", 'skim', 'Buttermilk, cultured']
boolean_idx = dairy_table["Food"].isin(food_names_list)
dairy_table['Food'].where(boolean_idx, other='Others')
Out[187]:
index0 Cows' milk, whole
index1 skim
index2 Buttermilk, cultured
index3 Others
index4 Others
......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment