新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

DataFrame和Series的排序-创新互联

更多大数据分析、建模等内容请关注公众号《bigdatamodeling》

创新互联从2013年开始,先为佛山等服务建站,佛山等地企业,进行企业商务咨询服务。为佛山企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
################################### 排序 ########################################
from pandas import DataFrame, Series
##### Series按索引排序 sort_index方法 返回新对象
obj = Series([1, 3, 2, 5, 6], index=list('dabce'))
obj.sort_index()
obj.sort_index(ascending=False)

##### Series按值排序 sort_values方法 返回新对象
obj.sort_values()
obj.sort_values(ascending=False)

##### DataFrame按引索引/列索引排序,
# 默认axis=0,行索引排序
# axis=1,列索引排序
frame = DataFrame(np.random.randn(4, 3), columns=list('dbe'),index=['Ut', 'Oh', 'Tex', 'Ore']) 
frame.sort_index() # 同frame.sort_index(axis=0) 
frame.sort_index(ascending=False)               
frame.sort_index(axis=1) 
frame.sort_index(axis=1, ascending=False) 

##### DataFrame按列排序
frame = DataFrame({'a': [1, 3, 1, 5], 'b': [2, 1, 4, 6]})
# sort方法 但只适用python2
frame.sort(columns=['a', 'b'], ascending=[True, True])
frame.sort(columns=['a', 'b'], ascending=[True, False])
# sort_index方法
frame.sort_index(by=['a', 'b'], ascending=[True, True])
frame.sort_index(by=['a', 'b'], ascending=[True, False])
# sort_values方法
frame.sort_values(by=['a', 'b'], ascending=[True, True])
frame.sort_values(by=['a', 'b'], ascending=[True, False])

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:DataFrame和Series的排序-创新互联
当前链接:http://www.wjwzjz.com/article/cdjgpo.html
在线咨询
服务热线
服务热线:028-86922220
TOP