在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