Learn everything about Analytics

Home ยป Emojize Your Data Science Projects

Emojize Your Data Science Projects

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('๐Ÿผ'))

Output:
Tomato: ๐Ÿ…
Italian tomato:
๐Ÿ… Demojized panda: :panda:

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.

You can also read this article on our Mobile APP Get it on Google Play