I am trying to replace the µ
with micro
in a string. It could replace some strings but it does not perform for some of them, for example, it changes 20.0+-1.8% hemolysis at 50µM
to 20.0+-1.8% hemolysis at 50microM
but it does not change it in this case: 0% hemolysis at 312 to 0μg/ml
. What could be the reason?
rep = {"±": "+-", "µ": "micro"}
rep = dict((re.escape(k), v) for k, v in rep.items())
pattern = re.compile("|".join(rep.keys()))
activity = pattern.sub(lambda m: rep[re.escape(m.group(0))], rows[i + 1].string.strip())
Even the replace()
did not change it:
activity = rows[i + 1].string.strip().replace('±','+-').replace('µ': 'micro')
Solution: The comment by @user2357112 could help to find a simple solution:
I changed the dictionary to this:
rep = {"±": " +- ", "µ": "micro", '\u03BC' : 'micro'}