Here I created a dictionary which maps old index to new index by adding values to a set to get unique values and then sorting in the ascending order which is required. After dictionary is formed, we can check if values in a particular row match with the data inside the dictionary, if it matches then that combination is correct and we don't do anything to that row, if it doesn't match we simply drop that row:
import pandas as pd
df = pd.DataFrame([[10, 390], [10, 395], [10, 405], [11, 390], [11, 395], [11, 405], [12, 390], [12, 395], [12, 405]], columns=['id', 'so_id'])
idx_map = {}
idx=set()
new_idx=set()
for row in df.iterrows():
idx.add(row[1]['id'])
new_idx.add(row[1]['so_id'])
for i in range(len(idx)):
idx_map[sorted(idx)[i]]=sorted(new_idx)[i]
for idx, row in df.iterrows():
if idx_map[row[0]]==row[1]:
continue
else:
df = df.drop(idx)
print(df)
Output
id so_id
0 10 390
4 11 395
8 12 405
Here, idx_map dictionary looks like this:
{10: 390, 11: 395, 12: 405}