How to remove emoji from the text in Python
Overview
In this Answer, weβll learn how to remove emojis from a text using the remove_emoji in Python.
The remove_emoji method is an in-built method, provided by the clean-text library in Python.
We can use it to clean data that has emojis in it. We need to install it from pip in order to use it in our programs:
pip install clean-text
Syntax
We can use the following syntax to use it:
from cleantext import clean
clean(text, no_emoji=True)
clean is the function provided by the cleantext library.
Parameter
To remove the emojis, we set the parameter no_emoji to True.
Example
Letβs look at an example:
#import clean functionfrom cleantext import clean#provide string with emojistext = "This sample text contains laughing emojis π π π π π π π π€£"#print text after removing the emojis from itprint(clean(text, no_emoji=True))
Explanation
In the code above:
- Line 1: We import the
cleanfunction from thecleantextpackage. - Line 5: We provide the text that has emojis in it.
- Line 8: We remove the emojis present in the
text. When the parameterno_emojiis set toTrue, thecleanfunction calls the in-builtremove_emoji()function.
Transform your ideas into high-quality videos with Soraβs AI-powered video generation. Ready to start creating? Visit our guide on Sora for more details!