Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
clean-text
communitycreator

How to remove emoji from the text in Python

Gutha Vamsi Krishna

Overview

In this shot, 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 function
from cleantext import clean

#provide string with emojis
text = "This sample text contains laughing emojis πŸ˜€ πŸ˜ƒ πŸ˜„ 😁 πŸ˜† πŸ˜… πŸ˜‚ 🀣"

#print text after removing the emojis from it
print(clean(text, no_emoji=True))
Removing emojis from text

Explanation

In the code above:

  • Line 1: We import the clean function from the cleantext package.
  • Line 5: We provide the text that has emojis in it.
  • Line 8: We remove the emojis present in the text. When the parameter no_emoji is set to True, the clean function calls the in-built remove_emoji() function.

RELATED TAGS

python
clean-text
communitycreator
RELATED COURSES

View all Courses

Keep Exploring