I have a Dataframe with a column called 'cleaned_tweet'. This column consists of tweets with several abbreviations and I want to replace those abbreviations with proper English words. For that, I have prepared a dictionary called 'slangs' where abbr. is the key and the desired English phrase/word as the value and I want to replace all the occurrences of those abbr. with their values in the dictionary. I have looked for several other solutions on stackoverflow but none of them seems to be working. Here is what I have tried. I am using a nested for loop and I believe I am quite close to the solution but I'm doing something wrong, which I can't seem to figure out.
Here's the nested loop:
for i in range(len(train_test_set)):
for j in slangs:
train_test_set['cleaned_tweet'][i] = train_test_set['cleaned_tweet'][i].replace(j, slangs[j])
when I executed this code and printed print(train_test_set['cleaned_tweet][0])
, I got an unexpected output like this:
"#mopanthank whyour | hi | years oldwhyour | hi | years oldhesitationospecial editekissas insekissperience wall hacken whyour | hi | years oldunited statesing a hallwhyour | hi | years olducinogenic drwhyour | hi | years olduglwhyour | hi | years oldung ladye rainbowhwhy | would whyour | hi | years olduohesitationents | rapper from atalk later | ekissperience wall hacken whyour | hi | years oldunited statesing a hallwhyour | hi | years olducinogenic drwhyour | hi | years olduglwhyour | hi | years oldung ladye rainbowhwhy | would whyour | hi | years olduoue loversatileionwhyes | yeah | yes | your | hi | years oldu | team leaderantaonwhysomethingop it | somethingwhyour | hi | years oldupid idiotake careal edwhyour | hi | years olducatekissas insekissperience wall hacken whyour | hi | years oldunited statesing a hallwhyour | hi | years olducinogenic drwhyour | hi | years olduglwhyour | hi | years oldung ladye..."
It seems many unwanted values are being appended to the cells. The output size is really big, so I can't copy it all here. Here is the structure of my dataset and dictionary before executing the code:
Can someone tell me what am I doing wrong?