Horje
python dataframe add rank column Code Example
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




Python

Related
openpyxl iter_rows skip first Code Example openpyxl iter_rows skip first Code Example
pppp Code Example pppp Code Example
vidgear python video streaming Code Example vidgear python video streaming Code Example
matplotlib bring plot to front in plots with twin axis Code Example matplotlib bring plot to front in plots with twin axis Code Example
Finding best model using GridSearchCV Code Example Finding best model using GridSearchCV Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7