πŸ“… Python can print calendars?!


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 (always) and print any month's calendar in a blink

In:
import calendar
print(calendar.month(2025, 9))
Out:
September 2025
Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

πŸ₯³ Looks cool right?

​

🌟 Anything stopping us from printing the full yearly calendar?

In:
print(calendar.calendar(2025))

Output will be something like below basis where you are running the code

​

🐸 Count number of leap years between two snapshots?

In:
print(calendar.leapdays(2000, 2025))
Out: 7

How many of you were born on Feb 29th?

​

🌞 Check weekday of a date

Starts from 0 (Monday) and ends at 6 (Sunday)

In:
print(calendar.weekday(2025, 9, 3))
Out: 2

​

πŸ€ Know month name

Starts from Jan whose index is 1

In:
print(calendar.month_name[9])
Out: September

​

πŸ˜‰ Days have names too

In:
print(calendar.day_name[0])
print(calendar.day_name[5])
Out:
Monday
Saturday

​

😎 Look cool by printing weekdays in short

In:
print(calendar.day_abbr[0])
Out: Mon

​

πŸš€πŸš€ Look Python pro by printing weekdays in number of letters needed

1 will print just 1 letter, same for 3

In:
print(calendar.weekheader(1))
print(calendar.weekheader(3))
Out:
M T W T F S S
Mon Tue Wed Thu Fri Sat Sun

β­πŸ“£ That's it for today! If you liked it, please share it with anyone who will find it useful 🐼🐼

​

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

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. 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] =...