The short answer: Yes, absolutely. For several decades now, a degree in computer science (or related field) has almost guaranteed employment, with good salaries, excellent benefits, and comfortable working conditions. […] The post Do programmers have a future? appeared first on LernerPython.
Tomorrow is Thanksgiving in the US. Use the “holidays” package to calculate its date in Python: The post Python holidays package: Find the date of Thanksgiving appeared first on LernerPython.
Let’s say you need a new shirt. In 2026, you have so many options for buying that shirt. You can shop online. You can (horrors!) go into a physical store. […] The post The end of enterprise software — or, a world of custom solutions appeared first on LernerPython.
Want your Python traceback to look nice? Use Rich: Now your tracebacks will be colorized and highlighted, with local variables clearly displayed and set apart (thanks to show_locals=True). The post Python tracebacks with Rich: Colorized output and local variables appeared first on LernerPython.
Is your Python program going to take a while? Use Rich to display animation while waiting: The status marker goes to the left of your text. See “python -m rich.spinner” […] The post Python loading spinners with Rich: Using Console.status appeared first on LernerPython.
Create beautiful tables in Python with Rich: # call once per column: # print it! The post Rich tables in Python: Using Table, add_column, and add_row appeared first on LernerPython.
Pass keyword args to the Python Rich console upon creation for consistent styling: The post Rich Console: Set default styles with keyword arguments appeared first on LernerPython.
Have a long Python string , and want to display it nicely? With Rich’s console, you can set the width or justification: The post Python Rich console: Setting text width and justification appeared first on LernerPython.
The “console” object in Python Rich lets you separate formatting from the text: The post Python Rich console: Separate style from text with Console.print appeared first on LernerPython.
At the FOSS4G UK 2026 conference in October, I gave a talk announcing that I’d re-released the Environment Agency DEM data for England in cloud-native formats. This was covering some work I did for my client Rebalance Earth and that we’ve decided to release openly. If you already know what I’m talking about then you […]
academicgisexcerpt only · body stays at the source
Want to set an option in Python Pandas, but just temporarily? You can use option_context: Within the “with” block, the display precision is 2. But outside — before or after […] The post Pandas option_context: Temporarily change display settings appeared first on LernerPython.
There are tons of config options in Python Pandas. Set them with pd.set_option: Now floats in a series or data frame will have 2 digits after the decimal. Retrieve the […] The post Pandas options: Setting display precision with pd.set_option appeared first on LernerPython.
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 […] The post Pandas 3.1 CSV loading: Multi-threaded, but PyArrow is still faster appeared first on LernerPython.
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 […] The post New course: Introduction to agentic coding with Claude Code appeared first on LernerPython.
Starting with Python Pandas 3.1, use “filter” to apply a condition to rows. So: can now be (the much slower): The post Pandas 3.1 filter: Selecting rows with a pd.col condition appeared first on LernerPython.
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 post Pandas 3.1 `select` method: Retrieving specific columns appeared first on LernerPython.
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, […] The post Python 3.15 comprehension unpacking: Why you can’t transform items appeared first on LernerPython.
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 […] The post Python set comprehension: Unique items from nested iterables appeared first on LernerPython.
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! The post Python 3.15 list unpacking: Flattening a nested list appeared first on LernerPython.
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. The post AI is programming’s next abstraction. What should we teach? appeared first on LernerPython.
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. […] The post Pandas multi-index: Working with 3D data using `.loc` and `.xs` appeared first on LernerPython.
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 […] The post Pandas droplevel: Remove a level from a multi-index appeared first on LernerPython.
What does a Python Pandas data frame’s multi-index look like? This: The post Pandas MultiIndex: What a two-level index looks like appeared first on LernerPython.
Using xs on a multi-indexed Python Pandas data frame drops the named level — unless you use drop_level=False: The post Pandas xs: Keep the dropped level with drop_level=False appeared first on LernerPython.
Using xs to retrieve from a Python Pandas multi-index? “level” takes an int or string: – int: The index level, with 0 the outermost– string: The level’s name — but […] The post Pandas xs: Using the `level` argument with an int or a name appeared first on LernerPython.
To retrieve all rows from a multi-indexed Python Pandas data frame or series based on the outermost index, use “loc”: The post Pandas MultiIndex: Select rows by the outer level with loc appeared first on LernerPython.
Using resample in Python Pandas? You’ll want a list of “offset aliases,” the codes that let you specify units. Some are surprising, such as “ME” and “MS” for “month end” […] The post Pandas offset aliases for resample: ME, MS, and other codes appeared first on LernerPython.
Announcing the Type Server Protocol and our partnership with Meta The post Pylance + Pyrefly: bring your preferred type checker to Visual Studio Code appeared first on Microsoft for Python Developers Blog.
Slice an unsorted datetime index in Python Pandas, and you’ll likely get: KeyError: ‘Value based partial slicing on non-monotonic DatetimeIndexes with non-existing keys is not allowed.’ Why? If the dates […] The post Pandas DatetimeIndex slicing: Fix KeyError with sort_index appeared first on LernerPython.
Want to select a chunk of time from a Python Pandas data frame? Make the datetime column the index, then use .loc and a slice to choose dates: The post Pandas date range selection: Slicing a datetime index with .loc appeared first on LernerPython.
Recently, some members of the Pulumi team spent time in San Francisco attending the CoreWeave: Fully Connected 2026 conference, where we had a chance to talk to everyone from solo developers to engineering leaders at Fortune 500 organizations and learn more about how they are building with AI. A frequent topic of conversation was open weight models and self-hosted inference. Whether AI is integrated into your platform, your product, or your productivity pipelines, rising token costs have decision makers everywhere giving open weight models a closer look, in exchange for the promise of tighter…
aikubernetesexcerpt only · body stays at the source
Got NaNs when using Grouper on a Python Pandas data frame? groupby+Grouper chops up the datetime values, from the earliest to the latest, by the specified granularity. If even one […] The post Pandas Grouper NaNs: Why outlier dates create empty groups appeared first on LernerPython.
Want to change the granularity when grouping on a Python Pandas data frame’s datetime column? Use Grouper. For example: Here we get the mean trip_distance per 14-day period: The post Pandas Grouper: Group datetime columns by custom time periods appeared first on LernerPython.
If your Python Pandas data frame has a datetime column, you can group on a portion of that via the “dt” accessor. For example, let’s get mean trip_distance for each […] The post Pandas groupby on datetime parts with the dt accessor appeared first on LernerPython.
Does Python Pandas allow multiple data columns and multiple methods? Yes! The above returns a data frame. Its 4 columns are a 2-level multi-index with mean/std in the inner level. The post Pandas groupby: Aggregating multiple columns with multiple functions appeared first on LernerPython.
Does Python Pandas allow multiple categorical columns and multiple methods? Yes! The above returns: – A 2-column data frame (mean + std)– A 2-level index (passenger_count + VendorID) The post Pandas groupby: Multiple columns and multiple aggregation methods appeared first on LernerPython.
groupby on a single column in Python Pandas returns a series. Want a single-column data frame? Instead of pass a one-element list of data columns: The post Pandas groupby: Get a data frame instead of a series appeared first on LernerPython.
Monte Carlo simulations (or methods) is the technique of applying randomness and the Law of large numbers to the solution of various scientific and engineering problems. One of its first documented uses was by Stanislaw Ulam and John von Neumann for nuclear weapon simulations after WWII [1]. In this post I want to provide examples of some simple uses of Monte Carlo simulations. We'll start with the classical example of calculating the value of \pi by throwing darts. Estimating pi Suppose we take a square board and inscribe a quarter of a circle into it. We then proceed to throw darts at the…
Invoke “groupby” with two categorical columns in Python Pandas, and get a two-part multi-index: Turn into a data frame with unstack: The post Pandas groupby with two columns: Reshape results with unstack appeared first on LernerPython.
A “groupby” call in Python Pandas is normally sorted by index. But if you’re grouping by month name, April will come before January. Pass “sort=False”, and the index will reflect […] The post Pandas groupby with sort=False: Keep groups in order of appearance appeared first on LernerPython.
The simplest grouping in Python Pandas is groupby: For example: Returns a series whose index is the unique values from passenger_count. The post Pandas groupby basics: Aggregating a numeric column by category appeared first on LernerPython.
My team develops a microservices application on Kubernetes, with hundreds of PRs opened each day. To let engineers test and review those changes in isolation before they’re merged, we give every pull request its own ephemeral environment. We use Pulumi to define those short-lived PR environments from a component resource that’s shared with our long-lived Dev, Stage, Prod environments. Each PR gets its own Pulumi stack and Kubernetes namespace, which we tear down once the PR is merged or closed. In this post, I’ll walk through how we’ve implemented this pattern and what we’ve learned from…
You can remove NaN from a Python Pandas data frame with dropna, but be careful: It removes rows with even one NaN, which can be overkill. Pass “thresh” to allow […] The post Pandas dropna with thresh: Drop only rows with too many NaN values appeared first on LernerPython.
Coming to Python Pandas from NumPy? You’ll reach for np.isnan: Unfortunately, this works. Better, use s.isna (or s.isnull). But the best way to drop NaN? Use dropna: The post Pandas dropna: The best way to remove NaN values from a series appeared first on LernerPython.
I’m a big fan of exercises, which is why the LernerPython platform includes hundreds of them — all using my in-browser practice system, which handles Python, Pandas, and Git, along […] The post New on the LernerPython practice system: A visual debugger appeared first on LernerPython.
PyArrow dtypes in Python Pandas are nullable (with pd.NA): s is: 0 101 2 30dtype: int64[pyarrow] The dtype is int64, but allows nulls. (Use np.nan? It’s turned into pd.NA.) The post PyArrow dtypes in pandas: Nullable integers with pd.NA appeared first on LernerPython.
You have a Python Pandas series with ints + NaN. You don’t want float forced on you. Solution: Use the “extension” type Int64 (note Initial Caps) and pd.NA: s is: […] The post Pandas nullable integers: Keeping ints with Int64 and pd.NA appeared first on LernerPython.
Python Workers allow developers to run Python web frameworks and AI orchestration libraries natively in the Cloudflare Workers runtime. You can seamlessly integrate with Cloudflare's ecosystem including D1, R2, and Workers AI without writing any JavaScript glue code.
Some of the most satisfying work I do happens one on one. You arrive with a real problem from your real job — code that will not behave, an architecture […] The post Get Python help, one on one: my coaching sessions appeared first on LernerPython.
Some of the most satisfying work I do happens one on one. You arrive with a real problem from your real job — code that will not behave, an architecture […] The post Get Python help, one on one: my coaching sessions appeared first on LernerPython.
Optional Google Analytics helps us understand visits. Microsoft Clarity records masked interactions to improve the site. Optional tools stay off unless you choose them. Privacy details.