Reuven M. Lerner
banner
lernerpython.com
Reuven M. Lerner
@lernerpython.com
Helping you become more confident with Python and Pandas since 1995.

• Courses: LernerPython.com
• Newsletters: BetterDevelopersWeekly.com • BambooWeekly.com
• Books: PythonWorkout.com • PandasWorkout.com
• Videos: YouTube.com/reuvenlerner
Pinned
Hi there! 👋 I'm Reuven, and I've been teaching #Python and Pandas around the world since 1995.

Just about every day, my students ask great questions. I love sharing those questions (and my answers), along with other resources to help you improve your Python/Pandas fluency.
How much oil does Venezuela export vs. Saudi Arabia?

Which country's exports are more highly correlated with oil prices?

And how much has oil consumption changed in Venezuela in the last 15 years?

We calculate it all, using #Python #Pandas, in the latest Bamboo Weekly!
January 15, 2026 at 7:52 PM
To sort a #Python #Pandas data frame by column x:

df.sort_values('x')

By x and y (ascending):

df.sort_values(['x', 'y'])

By x and y, both descending:

df.sort_values(['x', 'y'], ascending=False)

Ascending x, descending y:

df.sort_values(['x', 'y'], ascending=[True, False])
January 15, 2026 at 4:02 PM
In the latest Bamboo Weekly, we use #Python #Pandas to analyze Venezuelan oil production and consumption — including comparing their output with Saudi Arabia.

Improve your data skills with real data and current events! New questions every Wednesday. Solutions every Thursday.
January 14, 2026 at 6:32 PM
A #Python #Pandas rule of thumb: Wherever you can use a column name (string), you can use multiple column names (a list of strings):

df.set_index('x')
df.set_index(['x', 'y'])

df.groupby('last')
df.groupby(['last', 'first'])

df['x']
df[['x', 'y']] # Notice nested []
January 14, 2026 at 4:30 PM
Retrieve rows of a #Python #Pandas data frame with the 6 largest values of column x:

df.sort_values('x').tail(6)

Even better:

df.nlargest(n=6, columns='x')

Why is it better? On a 3m row, 680 MB data frame, sort/tail took 622 ms. nlargest? Only 84 ms — 7x faster!
January 13, 2026 at 4:31 PM
Why is #Python's join() a STRING method, not a list method?

x = 'this is a test'.split()

'*'.join(x)
':::'.join(x)

Not:

x.join('*')

Why not? The argument can be any string-returning iterable:

'*'.join('abcde')
'*'.join(str(x) for x in range(5))
'*'.join(open('filename.txt'))
January 12, 2026 at 4:30 PM
January 11, 2026 at 4:30 PM
Use parentheses to split long #Python code across lines:

if x == 10 and
y == 20:
print('Yes!') # ☹️

But with parentheses, Python sees it as one line:

if (x == 10 and
y == 20): # 🙂
print('Yes!')

Or in comprehensions…

[x*5
for x in range(10)
if x % 2]
January 10, 2026 at 4:30 PM
#Python Jupyter memory quirk: Deleting variables doesn't always free memory!

# cell 1
df = [YOUR BIG DATAFRAME]
df # View it + stores in Out[1]

# cell 2
del(df) # df deleted, but Out[1] still has it!

Use df.head() instead of df to keep big values out of Jupyter's Out dict.
January 9, 2026 at 4:31 PM
New York began congestion pricing in 2025. Also in 2025? Taxis and buses moved faster, and more people took public transportation.

We can prove it with the data — and using #Python #Pandas.

Challenge yourself with new, weekly real-world data problems: bambooweekly.com
January 9, 2026 at 5:15 AM
Playing NYT Spelling Bee? Use #Python to see if your word only uses allowed letters (ignoring length + center):

letters = set('ygoanik') # From Mon, Jan 5

With sets, <= checks "subset or equal":

set('again') <= letters # True
set('garage') <= letters # False (r + e)
January 8, 2026 at 4:30 PM
Congestion pricing went into effect in New York one year ago.

How did it affect traffic? Are buses faster than before?

The latest Bamboo Weekly asks you to answer these questions (and more) with Pandas.

Level up your data-analysis skills at bambooweekly.com
January 7, 2026 at 9:29 PM
Create a #Python dict with keys a/b/c and values 0:

d = dict.fromkeys('abc', 0)

But don't do this, since the value will be shared and mutable:

d = dict.fromkeys('abc', [])
d['a'].append('x')
d['b'].append('y')

print(d)

{'a': ['x', 'y'], 'b': ['x', 'y'], 'c': ['x', 'y']} 🤯
January 7, 2026 at 4:30 PM
"round" rounds #Python numbers:

round(1.3) # 1
round(1.6) # 2
round(1.61, 1) # 1.6
round(1.66, 1) # 1.7

Remember, .5 goes to the nearest *even* value:

round(1.5) # 2
round(2.5) # 2, yes 2! 🤯
round(3.5) # 4
round(1.65, 1) # 1.6
round(2.65, 1) # 2.6 🤯
round(3.65, 1) # 3.6
January 6, 2026 at 4:02 PM
Want to reverse a #Python sequence (string/list/tuple)? Use a 3-argument slice:

s[::-1]

This works because:

- Empty start means "from the start"
- Empty end means "through the end"
- Step size of -1 means "go back 1 each time"

This returns a new value, from s's end to its start.
January 5, 2026 at 4:30 PM
#Python is all about consistency. For example, sequences (string/list/tuple) all support:

s[i] # get 1 item
s[start:finish] # get slice
'a' in s # search
s.index('a') # where is a?
s.count('a') # how many as?

for item in s: # iterable
print(item)
January 4, 2026 at 4:30 PM
How can you tell if a #Python datetime is a weekend (i.e., Saturday or Sunday)?

Invoke weekday(). It returns an int; Mon is 0, Sat is 5 and Sun is 6. So:

today = datetime.datetime.now()
if today.weekday() > 4:
print('Weekend!')
else:
print('Not yet the weekend. :-(')"
January 3, 2026 at 4:30 PM
Consider this #Python:

>>> x = 100000
>>> y = 100000
>>> x is y
False

Surprised? That's because "is" is the wrong comparison:

• == asks: are these the same value?
• is asks: are these the same object?

You almost never care about question #2. And so, should rarely use "is".
January 2, 2026 at 4:30 PM
Want to make #Python numbers more readable? Use _ between digits (not at the start or end):

x = 1_000_000
y = 2_000
z = 1_000.234_567
January 1, 2026 at 4:30 PM
The new year is off to a great start: My printed copies of Python Workout just arrived!
January 1, 2026 at 12:53 PM
Wondering how Pandas 2 looks vs. Pandas 3?

In my latest video, I compare the spread of the flu in the US using both versions, comparing dtypes, memory usage, and query styles on real-life CDC data: youtu.be/1OqOM0FmFF0?...
January 1, 2026 at 9:17 AM
In the final Bamboo Weekly for 2025, we ask:

• Does PyCon US affect PyPI downloads?
• Is uv gaining traction?
• How fast are people adopting Python 3.14?

Check it out: bambooweekly.com
December 31, 2025 at 6:50 PM
Time zones are a pain to deal with! #Pandas 3 makes things a bit better by using the now-standard #Python zoneinfo module.

In this video, I show you what has changed — but also where/why time zones can cause so many headaches, and what Pandas 3 changed.

Check it out: youtu.be/Zekos7T2KI4?...
Time zones in Pandas: What Pandas 3 changes (and what it doesn't)
Time zones are hugely annoying to deal with. And in Pandas 3, they are changing! But to be honest, they're not changing that much: The big difference is that they'll use the Python standard library's…
youtu.be
December 31, 2025 at 2:52 PM
Nervous about upgrading #Pandas, because you don't know what'll break?

My latest video explains how Pandas is standardizing warnings, to make it clearer, now and in the future: youtu.be/lwBCX2FuB-4?...
Don't fear the upgrade: PDEPs and Pandas deprecations
Worried that upgrading to a new version of Pandas will break something? Or maybe you've gotten a warning from Pandas, and don't know when it'll really be a problem? In this video, I describe the way…
youtu.be
December 30, 2025 at 9:54 AM
Are you ready for #Python #Pandas 3.0?

Find out with my Pandas 3 playlist, youtu.be/TCSjgvtO714?....

New additions:

• Changes to sorted pd.concat and time series: youtu.be/2DVov1OfCFI?...
• Changed resample offsets: youtu.be/rZutMLQmWcY?...
Installing Pandas 3.0, using both uv and PyCharm
Pandas 3 upgrade playlist (start here): https://www.youtube.com/playlist?list=PLbFHh-ZjYFwFWHVT0qeg9Jz1TBD0TlJJT The Pandas 3.0 release candidate is out! How can you download and install it, to…
youtu.be
December 28, 2025 at 1:47 PM