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 β π₯ Ready, Get, Set, Go! Install and Import
In
!pip install humanize import humanize β π₯ Add commas to big numbers
In
n = 1234567890 print(humanize.intcomma(n)) print(humanize.intcomma(12345.67)) print(-humanize.intcomma(9876543))
Out
1,234,567,890 12,345.67 -9,876,543 β β»οΈ Large numbers to units
In
print(humanize.intword(1250000)) print(humanize.intword(2000)) print(humanize.intword(987000000))
Out
1.2 million 2.0 thousand 987.0 million β π Ranks, leaderboards that make sense
In
for i in [1, 2, 3, 11, 21, 101]: print(i, "β", humanize.ordinal(i))
Out
1 β 1st 2 β 2nd 3 β 3rd 11 β 11th 21 β 21st 101 β 101st β π File sizes that we understand
In
bytes_count = 3145728 print(humanize.naturalsize(bytes_count)) print(humanize.naturalsize(bytes_count, binary=True))
Out
3.1 MB 3.0 MiB β β³ Once upon a time!
In
from datetime import datetime, timedelta past = datetime.now() - timedelta(minutes=3, seconds=12) print(humanize.naturaltime(past))
Out
3 minutes ago β ποΈ Calendar labels
In
from datetime import date, timedelta import humanize d1 = date.today() d2 = date.today() - timedelta(days=1) d3 = date.today() - timedelta(days=45) print(humanize.naturaldate(d1)) # 'today' print(humanize.naturaldate(d2)) # 'yesterday' print(humanize.naturaldate(d3))
Out
'today' 'yesterday' Jul 25, 2025 β π€ Small numbers to words Does only till 9
In
for i in range(0, 12): print(i, "β", humanize.apnumber(i))
Out
0 β zero 1 β one 2 β two 3 β three 4 β four 5 β five 6 β six 7 β seven 8 β eight 9 β nine 10 β 10 11 β 11 β ποΈ Mini exercise
βπ£ 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. 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: Extract emojis Remove them if needed Replace with textual meaning Understand sentiment and what not... Let's begin!! Install demoji...
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...