soup = BeautifulSoup(data, 'html.parser')
for td in soup.select('td.thisIsMyClass'):
    td.replace_with(BeautifulSoup(replacement.format(text=td.a.text),
        'html.parser'))
print(soup.prettify())
Replacing tags of one kind with tags of another in BeautifulSoup