Sorting of Pandas Library Dataframe

Source: Internet
Author: User


DF1 is the test data for the DATAFRAME structure:


The DF1 data is read from the TEST.XLSX document, using the sample code as follows:

#-*-Coding:utf-8-*-import Tushare as Tsimport pandas as Pddf = Pd.read_excel (' test.xlsx ') df1 = Df.head (Ten) #dataframe按索引 In ascending order, the default is ascending #print df1.sort_index () #dataframe按索引降序排列 #print df1.sort_index (ascending=false) #第一行按升序排序, which is ascending by default #print Df1.sort_index (Axis=1) #第一行按降序排序 #print df1.sort_index (Axis=1, Ascending=false) #以amount这一列的值进行排序, default from small to large #print Df1.sort_values (by= ' amount ') #以amount这一列的值进行排序, from large to small #print df1.sort_values (by= ' Amount ', Ascending=false) #以多列排序, The values of the amount and price columns are sorted from large to small #print df1.sort_values (by=[' Amount ', ' price '], Ascending=false)











Sorting of Pandas Library Dataframe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.