Skip to content

Instantly share code, notes, and snippets.

@khurchla
Created July 15, 2022 13:46
Show Gist options
  • Save khurchla/9ca829cd2454f717434f9c965cc93406 to your computer and use it in GitHub Desktop.
Save khurchla/9ca829cd2454f717434f9c965cc93406 to your computer and use it in GitHub Desktop.
factorize string objects with python numpy courtesy of Matt
unique = np.unique(df[['Rank 1','Rank 2','Rank 3','Rank 78','Rank 79','Rank 80']])
factors = np.arange(len(unique))
df[['Rank 1','Rank 2','Rank 3','Rank 78','Rank 79','Rank 80']] = df[['Rank 1','Rank 2','Rank 3','Rank 78','Rank 79','Rank 80']].replace(unique, factors)
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment