Newsletter #286: Write Readable Multi-Condition Logic with Polars when-then-otherwise
Grab your coffee. Here are this week’s highlights.
📅 Today’s Picks
Write Readable Multi-Condition Logic with Polars when-then-otherwise
Problem
pandas requires np.where() for simple conditions which breaks method chaining and becomes nested and hard to read for multiple conditions.
The apply() alternative is slow and also breaks the DataFrame workflow.
Solution
Polars provides when().then().otherwise() chains that integrate naturally with method chaining.
With pandas, nested np.where() calls stack up for each additional condition, creating deeply nested expressions. Polars replaces this with readable chains where each condition appears sequentially.
Key benefits:
Natural flow with method chaining
Each condition stands on its own line
No nested function calls
Maintains data transformation workflow
The pattern scales cleanly from two conditions to ten without sacrificing readability.
Extract Text from Any Document Format with Docling
Problem
Have you ever needed to pull text from PDFs, Word files, slide decks, or images for a project? Writing a different parser for each format is slow and error-prone.
Solution
Docling‘s DocumentConverter takes care of that by detecting the file type and applying the right parsing method for PDF, DOCX, PPTX, HTML, and images.
Other features of Docling:
AI-powered image descriptions for searchable diagrams
Export to pandas DataFrames, JSON, or Markdown
Structure-preserving output optimized for RAG pipelines
Built-in chunking strategies for vector databases
Parallel processing handles large document batches efficiently
☕️ Weekly Finds
lm-evaluation-harness
[Machine Learning]
– Unified framework for testing and evaluating generative language models across a wide range of benchmarks and tasks with support for local models and custom metrics
PyMC
[Probabilistic Programming]
– Probabilistic programming library for Python that allows users to build Bayesian models with a simple Python API and fit them using state-of-the-art methods
Quarkdown
[Documentation]
– Modern Markdown typesetting system with powerful extensions for creating books, articles, and presentations. Supports function calls, custom functions, and outputs HTML, PDF, and slides
Looking for a specific tool? Explore 70+ Python tools →
Stay Current with CodeCut
Actionable Python tips, curated for busy data pros. Skim in under 2 minutes, three times a week.
.codecut-subscribe-form .codecut-input {
background: #2F2D2E !important;
border: 1px solid #72BEFA !important;
color: #FFFFFF !important;
}
.codecut-subscribe-form .codecut-input::placeholder {
color: #999999 !important;
}
.codecut-subscribe-form .codecut-subscribe-btn {
background: #72BEFA !important;
color: #2F2D2E !important;
}
.codecut-subscribe-form .codecut-subscribe-btn:hover {
background: #5aa8e8 !important;
}
.codecut-subscribe-form {
max-width: 650px;
display: flex;
flex-direction: column;
gap: 8px;
}
.codecut-input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: #FFFFFF;
border-radius: 8px !important;
padding: 8px 12px;
font-family: ‘Comfortaa’, sans-serif !important;
font-size: 14px !important;
color: #333333;
border: none !important;
outline: none;
width: 100%;
box-sizing: border-box;
}
input[type=”email”].codecut-input {
border-radius: 8px !important;
}
.codecut-input::placeholder {
color: #666666;
}
.codecut-email-row {
display: flex;
align-items: stretch;
height: 36px;
gap: 8px;
}
.codecut-email-row .codecut-input {
flex: 1;
}
.codecut-subscribe-btn {
background: #72BEFA;
color: #2F2D2E;
border: none;
border-radius: 8px;
padding: 8px 14px;
font-family: ‘Comfortaa’, sans-serif;
font-size: 14px;
font-weight: 500;
cursor: pointer;
text-decoration: none;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.3s ease;
}
.codecut-subscribe-btn:hover {
background: #5aa8e8;
}
.codecut-subscribe-btn:disabled {
background: #999;
cursor: not-allowed;
}
.codecut-message {
font-family: ‘Comfortaa’, sans-serif;
font-size: 12px;
padding: 8px;
border-radius: 6px;
display: none;
}
.codecut-message.success {
background: #d4edda;
color: #155724;
display: block;
}
@media (max-width: 480px) {
.codecut-email-row {
flex-direction: column;
height: auto;
gap: 8px;
}
.codecut-input {
border-radius: 8px;
height: 36px;
}
.codecut-subscribe-btn {
width: 100%;
text-align: center;
border-radius: 8px;
height: 36px;
}
}
Subscribe
Newsletter #286: Write Readable Multi-Condition Logic with Polars when-then-otherwise Read More »









