Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dataframe add rank column

df['default_rank'] = df['Number_legs'].rank()
>>> df['max_rank'] = df['Number_legs'].rank(method='max')
>>> df['NA_bottom'] = df['Number_legs'].rank(na_option='bottom')
>>> df['pct_rank'] = df['Number_legs'].rank(pct=True)
>>> df
    Animal  Number_legs  default_rank  max_rank  NA_bottom  pct_rank
0      cat          4.0           2.5       3.0        2.5     0.625
1  penguin          2.0           1.0       1.0        1.0     0.250
2      dog          4.0           2.5       3.0        2.5     0.625
3   spider          8.0           4.0       4.0        4.0     1.000
4    snake          NaN           NaN       NaN        5.0       NaN
Comment

PREVIOUS NEXT
Code Example
Python :: python split range into n groups 
Python :: find item in list 
Python :: django permissions 
Python :: python library 
Python :: save set of numpy arrays to file py 
Python :: prolog finding the max from a list of facts 
Python :: slicing in python list 
Python :: python any in string 
Python :: change a decimal to time in datetime python 
Python :: access element from list python 
Python :: print string python 
Python :: python if file exists append else create 
Python :: pandas loop over chunk of rows 
Python :: plot histogram from counts and bin edges 
Python :: with torch.no_grad() if condition 
Python :: how to start coding in python 
Python :: how to make an array python 
Python :: how can you know if a year is a leap year 
Python :: change increment in for loop python 
Python :: create array with shape 0,2 
Python :: Reverse an string Using Loop in Python 
Python :: pandas order dataframe by column of other dataframe 
Python :: remove figure label 
Python :: TypeError: method() takes 1 positional argument but 2 were given 
Python :: python autoclick website 
Python :: how to run python code in python 
Python :: implement stack using list in python 
Python :: how to get all values from class in python 
Python :: python combine two columns into matrix 
Python :: dictionary multiple values per key 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =