In this quick notes, we will have a look at Rank and Sort in Series and DataFrames in Python
In [1]:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
#make a series
ser1 = Series(range(3), index=['C','A','B'])
ser1
#sort index of series
ser1.sort_index()
#order or sort by values
ser1.order()
ser1.sort_values()
from numpy.random import randn
#make a series by passing in 10 random numbers
ser2 = Series(randn(10))
ser2
#sort the values
ser2.sort_values()
#rank the values #### meaning the values are actually sorted based on rank
ser2.rank()
#make a third series and generate 10 random numbers
ser3 = Series(randn(10))
ser3
#lets check the rank
ser3.rank()
#let's sort and then rank
ser3.sort_values()
ser3.rank()