raj chejara
raj chejara

Reputation: 11

Replacing emoji with text in python pandas?

How to replace the Values of the dictionary with the keys of the dictionary in the Data?

I have this dictionary

Dict = {' butterfly': "Ƹ̵̡Ӝ̵̨̄Ʒ'",
 ' clapping hands': "o/', '*o/*'",
 ' face with raised eyebrow': "O?O'",
 ' face with symbols on mouth': ">.'",
 ' grimacing face': "e.e', 'O.e', 'O.e'",
 ' rolling on the floor laughing': "m/*.*m/'"}

Keys = text/meaning of emoji, 
Values = emoji,

I want to replace the emoji(values) with the text(key) in my data.

Please suggest any better way to proceed.

sample data which has emoji....

.@AnnaKendrick47 My set up at the electronics boat at work. ^_^ "Fun update for everyone who's requested, #EW is now IN!! @WordsWFriends\n ⬇️ ⬇️ ⬇️ '@AnnaKendrick47 please sing @DrewGasparini \'s Circus""',

Upvotes: 1

Views: 466

Answers (1)

Jonathon McMurray
Jonathon McMurray

Reputation: 2981

One way would be like this:

>>> [k for k,v in Dict.iteritems() if v==">.'"]
[' face with symbols on mouth']

But if you can define the dictionary however you like, it would probably be better to do so with the emoji as the keys rather than the values. If you can't change the definition, you could define a second dictionary this way round:

>>> dict2 = dict(zip(Dict.values(),Dict.keys()))
>>> dict2[">.'"]
' face with symbols on mouth'

Upvotes: 2

Related Questions