это способ сделать .sort() нечувствительным к диакритическим знакам (знакам ударения, таким как á или ô). В настоящее время при сортировке я получаю «aeiou» перед «áéíóú», когда мне нужно «[aá][eé][ií][oó][uú]» или «aáeéiíoouú». Это мой код, хотя я сомневаюсь, что он имеет отношение к этому вопросу (язык был попыткой исправить это, предложенное Google Gemini):
Код: Выделить всё
import os
import locale
import polars as pl
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') # set the locale to en_US.UTF-8
# print the current working directory
print("Current working directory:", os.getcwd())
# Make paths for the lexicon and the sorted lexicon
LexiconPath = r'C:\Users\mawan\Documents\Code\WorldBuildingCode\KalagyonManNyal_Lexicon.csv'
UnsortedLexiconPath = r'C:\Users\mawan\Documents\Code\WorldBuildingCode\KalagyonManNyal_Lexicon_Sorted.csv'
# read the csv file name KalagyonManNyal_Lexicon and make it a DataFrame
df = pl.read_csv(LexiconPath)
df.fill_null("-") # fill null values with a dash
# print the first 5 rows of the DataFrame
print(df)
# sort the DataFrame by the column "Lexeme" in alphabetical order
df_sorted = df.sort("Lexeme")
print(df_sorted)
write_csv = df_sorted.write_csv(UnsortedLexiconPath, include_bom=True) # write the sorted DataFrame to a new csv file
# print(df.filter(df.is_duplicated())) # print duplicated rows
# print(df.columns)
# make a dataframe that filters by the part of speech input by the user
PoS = input("Enter the part of speech you want to filter by: ")
df_PoS = df.filter(df['PoS'] == PoS)
print(df_PoS)
Я попробовал использовать locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') после того, как Gemini, генеративный искусственный интеллект, предложил это, но, похоже, это ничего не изменило.>
Подробнее здесь: https://stackoverflow.com/questions/784 ... -in-python
Мобильная версия