Indexing or sorting dataframe using list

I wanted to sort the dataframe based on the list. Dataframe consists of unique id’s and I have a list of ids.

Note:- list not have all id’s value. I used df.loc but it has limitations.

Example code is as follows:

import pandas as pd
ratings_dict = {
    "ID": ["101", "102", "103", "104", "105"],
    "title": ['TV', 'AC', 'Monitor', 'Headphone', 'Laptop'],
    "rating": [1, 2, 2, 3, 2]

df = pd.DataFrame(ratings_dict)


trend_sort is the id list.


After using df.loc I got output as,

enter image description here

Expected output:

enter image description here


The only thing I can think of, is creating a new list like this:

sorted_list = trend_sort + [i for i in df.index.tolist() if i not in trend_sort]

and then:

df = df.loc[sorted_list]


    title   rating
103 Monitor   2
101 TV        1
102 AC        2
104 Headphone 3
105 Laptop    2