I want to exclude the Indexcolumn from the view of a Dataframe: I sort the whole dataframe based on the values (in decending order) and assign ranks. It perfectly works, however the indexcolumn is a bit misleading (especially in the ranking). I already tried to replace the Indexcolumn and used the column Rank as an index by using
df.set_index('Rank', inplace=True)
However, the sorting is then suspended and I may get a key Error if 2 persons (like here) have the same Rank. My code is:
from scipy.stats import rankdata
import pandas as pd
from tabulate import tabulate
names = ['Tim', 'Tom', 'Sam', 'Kyle']
values = [2, 4, 5, 4]
df = pd.DataFrame({'Name': names,'Values': values})
columns = ["Name", "Values"]
df['Rank'] = df['Values'].rank(method='dense', ascending=False).astype(int)
df.sort_values(by="Rank", ascending=True)