'Pandas replace value in column with key in dictionary

I'm trying to replace each value of a column in my pandas df with dict key if the value == the value of the dictionary:

Example dic: {'The Name of the Rose': '9780544176560'}

Example df:

ISBN, link
9780544176560, https://link

Code:

df['ISBN'] = df['ISBN'].astype(str)
for k,v in dic.items():
    for x in df['ISBN']:
        x = str(x)
        if x == v:
            print(True)
            x = k

It prints True every time, and if I print x I get the correct titles, but then when I print the df it returns numbers like nothing changed. I also tried replace but nothing changed



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source