在pandas dataframes中自定義排序
custom_dict = {'3月':0,'April':1,'dec':3} 將月列轉換為類別系列,指定自定義訂購:
)Sort the dataframe based on the categorical column:
df.sort_values("m")
custom_dict = {'March':0, 'April':1, 'Dec':3}
Using an Intermediary Series:
Prior to Pandas 0.15, you could utilize一個用於實現自定義排序的中間序列: 將自定義字典應用於“月”列: s = df ['m']。 InterMediary系列:
custom_dict = {'March':0, 'April':1, 'Dec':3}This method replaces the month values with the corresponding sorting values specified in the dictionary.基於修改月份列對數據框進行排序將獲得所需的自定義訂單。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3