-
-
Save andjc/d28411019877d6f5d79811263f886b4d to your computer and use it in GitHub Desktop.
Sort pandas dataframe using icu locale
This file contains hidden or 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 PyICU | |
# below from http://stackoverflow.com/questions/13838405/custom-sorting-in-pandas-dataframe | |
df = token_count | |
locale = 'UR.UTF-8' | |
collator = icu.Collator.createInstance(icu.Locale(locale)) | |
def sort_pd(key=None,reverse=False,cmp=None): | |
def sorter(series): | |
series_list = list(series) | |
return [series_list.index(i) | |
for i in sorted(series_list,key=key,reverse=reverse,cmp=cmp)] | |
return sorter | |
sort_by_custom_dict = sort_pd(key=collator.getSortKey) | |
df.iloc[sort_by_custom_dict(df.index)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment