Created
July 15, 2022 13:46
-
-
Save khurchla/9ca829cd2454f717434f9c965cc93406 to your computer and use it in GitHub Desktop.
factorize string objects with python numpy courtesy of Matt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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