In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame({'col1': [50, 80, 100, 80],
'col2': [0.3, pd.np.nan, 0.1, pd.np.nan],
'col3': ['h', 'j', 'i', 'k']},
index=['a', 'b', 'c', 'd'])
In [3]:
print(df)
In [4]:
print(df.rank())
In [5]:
print(df.rank(axis=1))
In [6]:
print(df.rank(numeric_only=True))
In [7]:
# print(df.rank(axis=1, numeric_only=False))
# TypeError: '<' not supported between instances of 'str' and 'int'
In [8]:
print(df.rank(ascending=False))
In [9]:
print(df.rank(method='average'))
In [10]:
print(df.rank(method='min'))
In [11]:
print(df.rank(method='max'))
In [12]:
# print(df.rank(method='first'))
# ValueError: first not supported for non-numeric data
In [13]:
print(df.rank(method='first', numeric_only=True))
In [14]:
print(df.rank(method='dense'))
In [15]:
print(df.rank(na_option='keep'))
In [16]:
print(df.rank(na_option='top'))
In [17]:
print(df.rank(na_option='top', method='min'))
In [18]:
print(df.rank(na_option='bottom'))
In [19]:
print(df.rank(na_option='bottom', method='min'))
In [20]:
print(df.rank(pct=True))
In [21]:
print(df.rank(pct=True, method='min', ascending=False, na_option='bottom'))
In [22]:
print(df['col1'].rank(method='min', ascending=False))