Emojis are widely used in modern digital communication, but sometimes you may want to convert them into text for data processing, sentiment analysis, or cleaning text data. In Python, this can be easily done using the demoji module.
Installation
You can install the demoji module using pip:
pip install demoji
Note: The demoji module requires downloading the latest emoji codes from the Unicode Consortium, as the emoji list is frequently updated.
import demoji
demoji.download_codes()
Using demoji to Convert Emojis into Text
Once the codes are downloaded, you can start converting emojis into descriptive text.
Example 1: Remove Emojis from Text
import demoji
text = "Good morning! βοΈπΈ"
a1 = demoji.replace(text, "")
print(a1)
Output:Β
Good morning!
Example 2: Replace Emojis with Descriptive Text
import demoji
text = "Happy birthday! ππ"
a1 = demoji.replace_with_desc(text)
print(a1)
Output
Happy birthday! :birthday cake::balloon:
Example 3: Detect Emojis in a String
import demoji
text = "Good morning βοΈπ"
emojis = demoji.findall(text)
print(emojis)
Output:Β
{'βοΈ': 'sun', 'π': 'smiling face with smiling eyes'}
Example 4: Remove All Emojis from Text
import demoji
text = "Welcome to the party! ππ₯³"
a1 = demoji.replace(text, "")
print(a1)
Output:Β
Welcome to the party!