Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use sort_index sorting in python pandas

Shulou Source: shulou.com Published: 2022-06-02 06:28:26 09月25日 Update

This article mainly introduces "how python pandas uses sort_index sorting". In daily operations, I believe many people have doubts about how python pandas uses sort_index sorting. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how python pandas uses sort_index sorting"! Next, please follow the editor to study!

The python pandas sort_index () method is specifically used to sort the index. Let's take a look at the specific usage:

# specified id column index column

> df=pd.read_excel (ringing DGV > myExcel > 1.xlsxx, index_col='id')

> df

Name score grade

Id

A bog 45.0 A

C jiken 67.0 B

I bob 23.0 A

B jiken 34.0 B

G lucy NaN A

E tidy 75.0 B

1. Sort rows by index

# rows index in ascending order

> > df.sort_index ()

Name score grade

Id

A bog 45.0 A

B jiken 34.0 B

C jiken 67.0 B

E tidy 75.0 B

G lucy NaN A

I bob 23.0 A

2. Row index in descending order

> df.sort_index (ascending=False)

Name score grade

Id

I bob 23.0 A

G lucy NaN A

E tidy 75.0 B

C jiken 67.0 B

B jiken 34.0 B

A bog 45.0 A

3. Index permutation for column

> df.sort_index (axis=1)

Grade name score

Id

An A bog 45.0

C B jiken 67.0

I A bob 23.0

B B jiken 34.0

G A lucy NaN

E B tidy 75.0

At this point, the study on "how python pandas uses sort_index sorting" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Sort learn method more help practical next ascending order articles theories knowledge articles websites materials follow questions easy to use practice solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB MySQL Xiaomi macOS