
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sort index in ascending order – Python Pandas
The sort_index() is used to sort index in ascending and descending order. If you won’t mention any parameter, then index sorts in ascending order.
At first, import the required library −
import pandas as pd
Create a new DataFrame. It has unsorted indexes −
dataFrame = pd.DataFrame([100, 150, 200, 250, 250, 500],index=[4, 8, 2, 9, 15, 11],columns=['Col1'])
Sort the indexes −
dataFrame.sort_index()
Example
Following is the code −
import pandas as pd dataFrame = pd.DataFrame([100, 150, 200, 250, 250, 500],index=[4, 8, 2, 9, 15, 11],columns=['Col1']) print"DataFrame...\n",dataFrame print"\nSort index...\n",dataFrame.sort_index()
Output
This will produce the following output −
DataFrame... Col1 4 100 8 150 2 200 9 250 15 250 11 500 Sort index... Col1 2 200 4 100 8 150 9 250 11 500 15 250
- Related Questions & Answers
- Python – Ascending Order Sort grouped Pandas dataframe by group size?
- Python Pandas - Sort DataFrame in ascending order according to the element frequency
- Python – Descending Order Sort grouped Pandas dataframe by group size?
- How to perform ascending order sort in MongoDB?
- Python Pandas - Return a Series containing counts of unique values from Index object sorted in Ascending Order
- Program to merge intervals and sort them in ascending order in Python
- How to sort Java array elements in ascending order?
- How can we sort MySQL output in ascending order?
- 8085 Program to perform bubble sort in ascending order
- 8085 Program to perform selection sort in ascending order
- Sort the MongoDB documents in ascending order with aggregation?
- Python program to sort out words of the sentence in ascending order
- Program to sort a given linked list into ascending order in python
- Python program to sort the elements of an array in ascending order
- How to sort an ArrayList in Java in ascending order?
Advertisements