Reading a CSV into a Python Pandas data frame? Before version 3.1, loading CSV was single-threaded and slow. My test file took 1.03s. In 3.1, it’s now multi-threaded and much faster, taking 252 ms. However, it’s still far slower than PyArrow, which took 25.5 ms.
I’m excited to announce my newest course, Introduction to agentic coding with Claude Code (https://lernerpython.com/courses/intro-agentic-coding-claude-code/). If you want to go beyond giving simple prompts or using Claude Code in trivial ways, this is the course for you. I’ve distilled what I’ve learned from using Claude Code every day for about a year to run my…
Starting with Python Pandas 3.1, use “filter” to apply a condition to rows. So: can now be (the much slower):
Want to retrieve specific columns from your Python Pandas data frame? In the past, you would say But now, with version 3.1, you can use the “select” method:
The comprehension-unpacking syntax in Python 3.15 is great, but you cannot transform the unpacked elements. Given: [[10, 20, 30], [40, 50, 60], [70, 80]] We can get the individual numbers, but cannot run str on each. For that, we still need a nested comprehension.
In Python 3.15, get the unique elements in a list of iterables with the new in-comprehension unpacking syntax to create a set comprehension: {*n for n in x} # returns {10, 20, 30, 40, 50, 60}
Want to unroll a nested list in Python 3.15? Use a nested list comprehension: Or use the new unpacking syntax: [*n for n in x] # same thing!
Programming has climbed from soldered wires to assembly to Python, and each new layer of abstraction has let more people solve bigger problems. AI coding is the next layer, and it changes what we should teach.
My students used to ask if Python Pandas supports 3D data structures. Answer: No. Series are 1D and data frames are 2D. But… a multi-index effectively gives you more dimensions. You can then navigate the indexes with .loc and .xs.
To remove a level from a Python Pandas multi-index, use droplevel: – “level” kwarg takes an int or string– “axis” kwarg can be “index” or “columns” — or use 0 or 1, but I prefer the names Returned data frame has the same number of rows, but index might have duplicates.