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.
Instead of choosing which #Python function to run with if/elif/else, use a dispatch table — a dict with functions as values:

from operator import add, sub, mul
ops = {'+':add, '-':sub, '*':mul}

s = input('Enter +, -, or * : ')
r = ops[s](10, 20)
print(f'10 {s} 20 = {r}')
February 12, 2026 at 4:30 PM
Woo hoo! 🎉

My book, #Python Workout (2nd edition), is now the #20 best-selling book in programming languages at Amazon.

Thanks so much to everyone who has bought it, and also to everyone leaving such kind reviews.
February 11, 2026 at 7:05 PM
Modern #Python dicts remember insertion order:

d = {'a':10, 'b':20, 'c':30}
list(d) # ['a', 'b', 'c']

d.pop('b') # remove 'b'
d['b'] = 99 # re-add 'b'
list(d) # ['a', 'c', 'b']

This applies in for loops, too!
February 11, 2026 at 4:30 PM
How corrupt is your country? The latest index from Transparency International was just released — and in the latest Bamboo Weekly, I pose 6 #Python #Pandas challenges for you to solve with that data.

New questions every Wednesday: bambooweekly.com
February 11, 2026 at 4:20 PM
Using #Python defaultdict? Don't pass a value:

d = defaultdict(0) # ❌ Error!

Pass a function that returns the default:

d = defaultdict(int) # int() returns 0
d = defaultdict(list) # list() returns []
d = defaultdict(dict) # dict() returns {}
February 10, 2026 at 4:30 PM
Your #Python function takes a filename and **kwargs. But this raises an error, since "filename" is passed twice:

myfunc('outfile.txt', filename='abcd', x=100)

Solution: Set filename to be positional only:

def myfunc(filename, /, **kwargs):

Now *any* keyword argument works!
February 9, 2026 at 4:30 PM
Break a #Python string into a list of strings with str.split:

s = 'ab cd ef'

s.split() # ['ab', 'cd', 'ef']

Limit splits with maxsplit:

s.split(maxsplit=1) # ['ab', 'cd ef']

Or split from the right, with a limit:

s.rsplit(maxsplit=1) # ['ab cd', 'ef']
February 8, 2026 at 4:30 PM
Reposted by Reuven M. Lerner
fun fact (or opinion...?) friday: @lernerpython.com's python workout, second edition can help fight AI brain rot.

source (via linkedin): hubs.la/Q042bvtT0

the book:
• on manning: hubs.la/Q042bwqc0
• on amazon: hubs.la/Q042bwGq0
February 6, 2026 at 10:36 PM
Tired of super-long #Python #Pandas backtraces in Jupyter or IPython? Use the %xmode magic method:

%xmode Minimal

Now you just see the error, not 50 lines of library internals.

You can also set it to Plain, Context, or Verbose.
February 7, 2026 at 4:30 PM
Joining #Python #Pandas DataFrames with overlapping columns? You'll hit:

ValueError: columns overlap but no suffix specified

Fix with lsuffix and rsuffix:

df1.join(df2, lsuffix='_left', rsuffix='_right')

Now the columns are: x_left, x_right, y_left, y_right

Problem solved!
February 6, 2026 at 4:30 PM
Want to learn #Python, but new to coding?

Most books expect too much. But not my new "AI-Assisted Python for Nonprogrammers"!

It's meant for you. And uses AI to help you learn, *not* to write code for you.

Check it out, in early release: buff.ly/4BCUU49
February 6, 2026 at 2:00 PM
Think you can't modify a #Python list while iterating? You can append to it:

mylist = [10, 20, 30]
for i in mylist:
print(i)
if i < 100:
mylist.append(i ** 2)

This prints 10, 20, 30, 100, 400, and 900.

BUT don't insert or remove. That'll cause real trouble.
February 5, 2026 at 4:31 PM
Bamboo Weekly is 3 years old!

• New #Python #Pandas challenges every Wednesday
• Real-world data sets
• Topics from current events
• Detailed solutions and explanations every Thursday

Learn pandas the way it sticks — by solving real problems with real data.
February 5, 2026 at 11:29 AM
Happy 3rd anniversary, Bamboo Weekly!

This is issue 156, marking 3 years of weekly Pandas challenges.

This week, we look at Winter Olympic data. Since they love snow so much, we'll use #Polars along with #Python #Pandas.

Check it out, at bambooweekly.com.
February 4, 2026 at 7:27 PM
Think #Python functions can return multiple values? They actually return ONE value, a tuple:

def sum_and_mean(nums):
return sum(nums), sum(nums)/len(nums)

Unpack it into separate variables:

num_sum, num_mean = sum_and_mean([10, 20, 25])
February 4, 2026 at 4:30 PM
Let users assign using [] in #Python, with custom logic with __setitem__:

class StringList:
def __init__(self, d):
self.d = d
def __setitem__(self, i, v):
self.d[i] = str(v)

sl = StringList(['2', '4', '6', '8'])
sl[2] = 99

sl.d
['2', '4', '99', '8']
February 3, 2026 at 4:30 PM
The __getitem__ method in #Python can do more than simple lookups:

class DoubleIndex:
def __getitem__(self, i):
return i * 2

d = DoubleIndex()
d[5] # returns 10

Use [] for custom logic — returning filenames, random numbers, or database records.
February 2, 2026 at 4:31 PM
Want your #Python object to support bracket notation []? Define __getitem__:

class MyList:
def __init__(self, items):
self.items = items
def __getitem__(self, i):
return self.items[i]

m = MyList([1,2,3])
m[0] # returns 1
February 1, 2026 at 4:30 PM
#Python #Pandas gotcha: You can't join a single column!
df1['x'].join(df2) # Error!

Why? join() is a data frame method. A single column is a Series.

Solution: Use [[ ]] to get a one-column data frame:
df1[['x']].join(df2) # Works!
January 31, 2026 at 4:30 PM
I used #Python #Pandas to total AWS S3 payments.

Data was in a CSV file. But numbers in the "Amount" column were written as "USD 12.34".

Here's what I did:

(
df['Amount']
.str.replace('USD', '') # remove "USD"
.astype(float) # no strip needed!
.sum()
)
January 30, 2026 at 4:30 PM
Gold prices have gone up recently — but by how much?

In the latest Bamboo Weekly, we use #Python and #Pandas to find out. Then we compare its price with silver, and with central banks' gold and dollar holdings.

Get data analysis puzzles every Wednesday: bambooweekly.com
January 29, 2026 at 6:59 PM
#Python gotcha: Forgetting () on method calls!

d = {'a':2, 'b':4}

list(d.items()) # ✅ calls method

list(d.items) # ❌ passes method object

Result:

Error: 'builtin_function_or_method' object is not iterable

Remember: () calls the method!
January 29, 2026 at 4:30 PM
Still writing #Python yourself? That's so 2025! Many developers now code via AI.

In my AI-Powered workshops, you'll solve problems using Claude Code. We'll discuss prompts, code output, and testing, and the implications.

Hear more at my free info session today (Thursday): buff.ly/Rs7J4Eh
January 29, 2026 at 8:42 AM
Gold! Its price is soaring. 📈

In Bamboo Weekly, we use #Python #Pandas to look at its price, compared with silver, and as a proportion of central bank holdings.

Improve your data-analysis skills every Wednesday, with challenges based on current events, using real-world data sets: buff.ly/kU1JxPZ
January 28, 2026 at 11:33 PM
#Python #Pandas 3.0 introduces pd.col, which shortens queries:

df.loc[lambda df_: df_['age'] > 10] # pre-3.0
df.loc[pd.col('age') > 10] # 3.0

Also:

df.assign(xy = lambda df_: df_['x'] * df_['y']) # pre-3.0
df.assign(xy = pd.col('x') * pd.col('y')) # 3.0
January 28, 2026 at 4:30 PM