Last active
November 7, 2018 23:45
-
-
Save socratesk/23be733017f6d6adc721f00842d47b56 to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
managerDF = pd.DataFrame({'id':[101, 102, 103, 104, 105, 106, 107, 108], | |
'managerId':['D025', 'A010', 'C020', 'A010', 'D025', 'D025','A010', 'D025']}) | |
# Group by category (managerId), compute sum of values in the category, sort by sum, and rank each value | |
idRank = managerDF.groupby('managerId').size().sort_values().rank().map(int) | |
# Map the ranks of items in the category to its respective item | |
managerDF['managerIdRank'] = managerDF['managerId'].map(idRank) | |
# Cleanup unwanted features | |
managerDF.drop(['managerId'], axis=1, inplace=True) | |
print(managerDF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment