Emojize Your Data Science Projects

Elena Last Updated : 30 Oct, 2024
5 min read

This article was published as a part of the Data Science Blogathon

Introduction

Our world is becoming more and more digital, especially after pandemic times. One of the consequences of this global trend is the overflooding of emoticons. Nowadays, they are literally omnipresent, and people feel almost obliged to use them. If you send a message to a friend and don’t use any emoji there, that person can become even worried whether everything is ok, if you’re not offended, etc.

Since emoticons are so widespread and trendy now, why don’t we use them in our data science or data analysis projects to give zest to our storytelling? Indeed, we can, and in this article, we’ll explore how.

Emoji

Installation: pip install emoji

With this Python library, we can convert strings to emoji, according to the Emoji codes as defined by the Unicode Consortium. Besides, there is a possibility to expand the list of available emoticons supported by the current version of the package by adding the aliases, using the optional parameter use_aliases=True.

This small module has only two functions: emojize() and demojize(). The default language is English (language='en'), but it’s possible to switch to Spanish ('es'), Portuguese ('pt'), or Italian ('it').

This small module has only two functions: emojize() and demojize(). The default language is English (language='en'), but it’s possible to switch to Spanish ('es'), Portuguese ('pt'), or Italian ('it').

В [1]:

import emoji

print('Tomato: ', emoji.emojize(':tomato:'))
print('Italian tomato: ', emoji.emojize(':pomodoro:', language='it'))
print('Demojized panda: ', emoji.demojize('🐼'))
 

Demojizing some emoticons can be tricky, though. For example, what we would logically call a squirrel, is actually encoded as :chipmunk:, so the code emoji.emojize(':squirrel:') will not return any emoji (with or without using the list of aliases), only the input string. In addition, some coded emoticons are not the same in the Unicode list and list of aliases. They can differ in just one symbol, e.g. an underscore:

В [2]:
 
print(emoji.emojize(':tophat:'))
print(emoji.emojize(':tophat:', use_aliases=True))
print(emoji.emojize(':top_hat:'))
print(emoji.emojize(':top_hat:', use_aliases=True))
 
Output:
 
 
 
 

:tophat: 

 

Since ':tophat:' doesn’t exist in the Unicode list, the library will just return the input as an output (':tophat:'). However, the list of aliases exists, so if we add this list, we’ll obtain the corresponding emoji. On the other hand, the version with an underscore (':top_hat:') is present in the Unicode list and absent in the list of aliases. Hence, whether we use the additional list or not, we’ll get the emoticon of a hat anyway, and it will derive from the Unicode list.

Emojis

Installation: pip install emojis

Emojis is another Python library for converting emoticons to words and vice versa. As a source of emoji, it uses Emoji Cheat Sheet, which is practically the same list of aliases that we saw earlier. This module has two main functions encode() and decode() that are similar in their meaning and syntax to the ones of the previous module. In addition, it offers some other functions:

  • get(str) – returns unique emoticons from the input string,
  • iter(str) – iterates over all emoji found in the input string,
  • count(str) – counts all the emoticons in the input string. It’s also possible to count only unique values passing in an optional parameter unique=True.

Unlike the previous library, the only available language here is English.

В [3]:
 
import emojis
print('Encoded heart: ', emojis.encode(':gift_heart:'))
print('Decoded candy: ', emojis.decode('🍬'))
print('--------------------------------------------------')
zoo = 'In our zoo, there are 🐒🐨🐙🐒🐷🐨🐙🐉🐙🐷🐨🐷🐉🐒'
print('Number of animals in the zoo: ', emojis.count(zoo))
print('Unique animals in the zoo: ', emojis.get(zoo))
print(‘Number of unique animals: ‘, emojis.count(zoo, unique=True))

 

Output:

Encoded heart: 💝 

Decoded candy: :candy: 

————————————————– 

Number of animals in the zoo: 14 

Unique animals in the zoo: {‘🐒’, ‘🐙’, ‘🐉’, ‘🐨’, ‘🐷’} Number of unique animals: 5 

 

Besides, there are some database functions:

  • db.get_emoji_aliases() – returns all emoji as a dictionary,
  • db.get_categories() – all categories available,
  • db.get_tags() – all tags available,
  • db.get_emoji_by_alias(alias) – all the information about a selected alias (emoji, category, tag, Unicode version),
  • db.get_emojis_by_category(category) – all emoji related to a selected category as an iterable object,
  • db.get_emojis_by_tag(tag) – all emoji related to a selected tag as an iterable object,

etc.

В [4]:
print('All categories: ', emojis.db.get_categories())
print('--------------------------------------------------')
print('Number of emoji: ', len(emojis.db.get_emoji_aliases()))
print('Number of tags: ', len(emojis.db.get_tags()))
print('--------------------------------------------------')
print('Alias "cake": ', emojis.db.get_emoji_by_alias('cake'))
print('--------------------------------------------------')
print('Category "Smileys & Emotion": ',
      [item[1] for item in emojis.db.get_emojis_by_category(category='Smileys & Emotion')])
print('--------------------------------------------------')
print('Tag "christmas": ',
      [item[1] for item in emojis.db.get_emojis_by_tag('christmas')])
 
Output:
 
All categories: {‘Food & Drink’, ‘Flags’, ‘People & Body’, ‘Travel & Places’, ‘Activities’, ‘Smileys & Emotion’, ‘Animals & Nature’, ‘Symbols’, ‘Objects’} 

————————————————– 

Number of emoji: 1848 

Number of tags: 447

————————————————– 

Alias “cake”: Emoji(aliases=[‘cake’], emoji=’🍰’, tags=[‘dessert’], category=’Food & Drink’, unicode_version=’6.0′)

————————————————–

Category “Smileys & Emotion”: [‘😀’, ‘😃’, ‘😄’, ‘😁’, ‘😆’, ‘😅’, ‘🤣’, ‘😂’, ‘🙂’, ‘🙃’, ‘😉’, ‘😊’, ‘😇’, ‘🥰’, ‘😍’, ‘🤩’, ‘😘’, ‘😗’, ‘☺️’, ‘😚’, ‘😙’, ‘U0001f972’, ‘😋’, ‘😛’, ‘😜’, ‘🤪’, ‘😝’, ‘🤑’, ‘🤗’, ‘🤭’, ‘🤫’, ‘🤔’, ‘🤐’, ‘🤨’, ‘😐’, ‘😑’, ‘😶’, ‘😏’, ‘😒’, ‘🙄’, ‘😬’, ‘🤥’, ‘😌’, ‘😔’, ‘😪’, ‘🤤’, ‘😴’, ‘😷’, ‘🤒’, ‘🤕’, ‘🤢’, ‘🤮’, ‘🤧’, ‘🥵’, ‘🥶’, ‘🥴’, ‘😵’, ‘🤯’, ‘🤠’, ‘🥳’, ‘U0001f978’, ‘😎’, ‘🤓’, ‘🧐’, ‘😕’, ‘😟’, ‘🙁’, ‘☹️’, ‘😮’, ‘😯’, ‘😲’, ‘😳’, ‘🥺’, ‘😦’, ‘😧’, ‘😨’, ‘😰’, ‘😥’, ‘😢’, ‘😭’, ‘😱’, ‘😖’, ‘😣’, ‘😞’, ‘😓’, ‘😩’, ‘😫’, ‘🥱’, ‘😤’, ‘😡’, ‘😠’, ‘🤬’, ‘😈’, ‘👿’, ‘💀’, ‘☠️’, ‘💩’, ‘🤡’, ‘👹’, ‘👺’, ‘👻’, ‘👽’, ‘👾’, ‘🤖’, ‘😺’, ‘😸’, ‘😹’, ‘😻’, ‘😼’, ‘😽’, ‘🙀’, ‘😿’, ‘😾’, ‘🙈’, ‘🙉’, ‘🙊’, ‘💋’, ‘💌’, ‘💘’, ‘💝’, ‘💖’, ‘💗’, ‘💓’, ‘💞’, ‘💕’, ‘💟’, ‘❣️’, ‘💔’, ‘❤️’, ‘🧡’, ‘💛’, ‘💚’, ‘💙’, ‘💜’, ‘🤎’, ‘🖤’, ‘🤍’, ‘💯’, ‘💢’, ‘💥’, ‘💫’, ‘💦’, ‘💨’, ‘🕳️’, ‘💣’, ‘💬’, ‘👁️u200d🗨️’, ‘🗨️’, ‘🗯️’, ‘💭’, ‘💤’]

————————————————– 

Tag “christmas”: [‘🎅’, ‘☃️’, ‘🎁’]

 

 

Emoji Websites

If we just need to locally insert a few emoticons in our project, probably it’s better to avoid all this coding hassle and use ready copy-paste websites with emoji collections: Emojipedia, Emojicopy, Emojikeyboard, Getemoji, etc. Usually, these resources provide a search system, filters, divide all the emoticons into categories. Some of such websites have also specific features. For example, Emojipedia displays how each emoji looks on different devices, gives its short description, and alternative names. Emojikeyboard shows related emoji, keywords, Unicode, CSS, and HTML code, version information.

ASCII Text Art

Finally, if emoticons are not enough to express all our feelings in data science projects 😉, we can consider using ASCII text art: an arrangement of letters, numbers, or special characters that makes a decorative text, or one-line / multi-line visual shape. There is a helpful library Art for these purposes in Python, but probably in the majority of cases, it will be enough just to copy and paste some text art elements in our project. We can use directly the lists provided by this library: art elements and decorations. Otherwise, there are plenty of other collections of ASCII pieces on the Internet. Some of such text art elements look quite funny or sophisticated:

cheers ( ^_^)o自自o(^_^ )
fish swim ¸.·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> 

How can these pieces be used in data science projects? For example, they can be put on top of some visualizations to better show their components. You can get inspiration from this article, where ASCII art elements were successfully applied in the section on Venn diagrams (4. Venn Diagram). Used in this way, they help to percept the main idea more efficiently than if we would use words instead.

Conclusion

To sum up, we explored several curious ways of making our projects more impressive and vivid. Of course, we should always be careful with emojis and decorations, using them only sporadically and appropriately.

Thanks for reading, and happy emojizing! 🙂

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details