0

i have a lot of text data like this in excel files raw data

and a list of dictionary from slang or abbreviations word in Indonesia from txt files slang/abbreviation word

How to replace the word in the text based on the dictionary that i've made before?

  • Please do not share picture of text. You can instead edit your question and copy paste some rows of your dataframe and some lines of you slang dictionnary. Also consider adding the `nlp` (natural language processing) tag. – ygorg Apr 16 '21 at 14:46
  • Thankyou for the feedback. I cant add nlp because my repution isnt sufficient for that. You can help me by answering that asap because I need the answer – ramdanirizki Apr 17 '21 at 13:28

1 Answers1

0

You can do it in this way (this an example for one string):

string = 'asd des sdss d'
replacements = {"asd": "replaced"}
new_string = " ".join(replacements.get(word, word) for word in string.split(' '))
print(new_string)

result: 'replaced des sdss d'

This does not take care of special characters in the text like ',' or '.'. Maybe you need to add logic to take care of these things.

Franco Morero
  • 549
  • 5
  • 20