Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. β Amazon reviews, chats and social media text (posts, comments, stories etc) are full of emojis π₯π₯ Great for expression! But give a hard time for text interpretation (Amazon, Meta would be going crazy). That is where Python's demoji library comes in. From a given text you can:
Let's begin!! β Install demoji library Don't worry if you don't know "pip" for now
In:
!pip install demoji # install once in notebooks
Out:
Collecting demoji Downloading demoji-1.1.0-py3-none-any.whl (42 kB) Installing collected packages: demoji Successfully installed demoji-1.1.0 β Import like we do for other modules
In:
import demoji demoji.download_codes() # download latest emoji description (run once)
Out: codes downloaded to β¦/demoji/codes.json
β Find which emojis are present and their meaning
In:
text = "Great food π but service was slow π" print(demoji.findall(text))
Out: {'π': 'face savoring food', 'π': 'confused face'}
β Replace emojis with their description Emoji description can provide valuable info during text analysis
In:
desc = demoji.replace_with_desc("That goal was π₯π₯") # keep meaning in plain text print(desc)
Out: That goal was :fire::fire:
β Remove them completely Used when we only want to focus on text
In:
clean = demoji.replace("Homework done π π", "") print(clean)
Out: Homework done
β Find different types of emojis used
In:
count = len(demoji.findall("ππ That's hilarious!")) print(count)
Out: 1
β Get meaning of first emoji only Capture emotion instantly
In:
text = "So happy today π" meaning = list(demoji.findall(text).values())[0] print(meaning)
Out: smiling face with heart-eyes
β Convert emoji to sentiment
In:
text = "Movie was π but ending was π‘" mapped = demoji.replace_with_desc(text) mapped = mapped.replace(":thumbs up:", ":positive:") mapped = mapped.replace(":pouting face:", ":negative:") print(mapped)
Out: Movie was :positive: but ending was :negative:
β Find if text has emoji
In:
text = "Refund now!!! π‘" has_emoji = bool(demoji.findall(text)) print(has_emoji)
Out: True
β Extract all emojis
In:
emojis = "".join(demoji.findall("Trip was great ποΈπΉβοΈ").keys()) print(emojis)
Out: ποΈπΉβοΈ
βπ£ That's it for today! If you liked it, please share it with anyone who will find it useful πΌπΌ β |
Beginner to Expert in Python in just 5 minutes
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. We all agree that dashboards, emails, logs should read like English. Meaning 1.2 million beats 1234567 and 3.1M is more readable than 3145728. Stakeholders scan - and they get pissed if they have to parse messy numbers ππ So today, we explore a third-party humanize library. Format numbers, file sizes, and dates/times into human-readable text. Mini exercise at the end. π₯ Ready, Get, Set, Go! Install and...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. We all know Pythonβs basic container data types β lists, dictionaries, tuples, sets. "Container" is just a data type that holds multiple items instead of single values. However, many times basics are not enough. Like if you want count of different items in the list you will run a loop like below. In: fruits = ["apple", "banana", "apple", "cherry"] counts = {} for item in fruits: counts[item] =...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Do you want to outsmart your friends (and interviewers) with Python? Couple of weeks back we played around with date and time using datetime module. Guess what - Python has another super handy module: calendar. Allows you to do all things related to calendars - like literally printing it in a readable form too. And its extremely simple to learn! Yet not many do it π Lets Go ππ β¨ Import calendar module...