Skip to content

Instantly share code, notes, and snippets.

@aqd14
Created February 22, 2020 03:53
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 aqd14/73c5a11ce2cc55ce28c2f558381c2c78 to your computer and use it in GitHub Desktop.
Save aqd14/73c5a11ce2cc55ce28c2f558381c2c78 to your computer and use it in GitHub Desktop.

Notes

// Assume we have a 'gender' column with only M and F values
// solution 1
users['gender_n'] = [1 if gender == 'M' else 0 for gender in users['gender']]

// solution 2
users['gender_n'] = np.where(users['gender'] == 'M', 1, 0)

// solution 3
users['gender_n'] = (users['gender'] == 'M').astype(int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment