or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

column-selection.mdconfiguration.mdcore-data-structures.mddata-conversion.mddata-types.mderror-handling.mdfunctions-expressions.mdindex.mdio-operations.mdsql-interface.md

functions-expressions.mddocs/

0

# Functions and Expressions

1

2

90+ utility functions for data construction, aggregation, statistical operations, and expression building with support for vectorized computations, window functions, and complex data transformations.

3

4

## Capabilities

5

6

### Construction Functions

7

8

Functions for creating expressions, literals, and data structures from various inputs.

9

10

```python { .api }

11

def col(name: str) -> Expr:

12

"""

13

Create a column expression for referencing DataFrame columns.

14

15

Parameters:

16

- name: Column name or pattern (* for all columns)

17

18

Returns:

19

Column expression

20

"""

21

22

def lit(value, dtype=None, *, allow_object=False) -> Expr:

23

"""

24

Create a literal expression from a value.

25

26

Parameters:

27

- value: Literal value (scalar, list, etc.)

28

- dtype: Explicit data type

29

- allow_object: Allow Python objects

30

31

Returns:

32

Literal expression

33

"""

34

35

def struct(*exprs, **named_exprs) -> Expr:

36

"""

37

Create a struct expression from multiple expressions.

38

39

Parameters:

40

- exprs: Expressions to include as fields

41

- named_exprs: Named expressions as keyword arguments

42

43

Returns:

44

Struct expression

45

"""

46

47

def field(name: str) -> Expr:

48

"""

49

Access a field from a struct expression.

50

51

Parameters:

52

- name: Field name

53

54

Returns:

55

Field access expression

56

"""

57

58

def element() -> Expr:

59

"""

60

Access elements from a list expression context.

61

62

Returns:

63

Element access expression

64

"""

65

```

66

67

### Aggregation Functions

68

69

Functions for computing summary statistics and aggregations across data.

70

71

```python { .api }

72

def sum(*names: str) -> Expr:

73

"""

74

Sum values across expressions.

75

76

Parameters:

77

- exprs: Expressions to sum

78

79

Returns:

80

Sum expression

81

"""

82

83

def mean(*columns: str) -> Expr:

84

"""

85

Calculate mean across expressions.

86

87

Parameters:

88

- exprs: Expressions to average

89

90

Returns:

91

Mean expression

92

"""

93

94

def median(*exprs) -> Expr:

95

"""

96

Calculate median across expressions.

97

98

Parameters:

99

- exprs: Expressions to find median

100

101

Returns:

102

Median expression

103

"""

104

105

def max(*names: str) -> Expr:

106

"""

107

Find maximum value across expressions.

108

109

Parameters:

110

- exprs: Expressions to find max

111

112

Returns:

113

Maximum expression

114

"""

115

116

def min(*names: str) -> Expr:

117

"""

118

Find minimum value across expressions.

119

120

Parameters:

121

- exprs: Expressions to find min

122

123

Returns:

124

Minimum expression

125

"""

126

127

def count(*columns: str) -> Expr:

128

"""

129

Count non-null values across expressions.

130

131

Parameters:

132

- exprs: Expressions to count

133

134

Returns:

135

Count expression

136

"""

137

138

def len(*exprs) -> Expr:

139

"""

140

Count all values (including nulls) across expressions.

141

142

Parameters:

143

- exprs: Expressions to count

144

145

Returns:

146

Length expression

147

"""

148

149

def std(column: str, ddof: int = 1) -> Expr:

150

"""

151

Calculate standard deviation of a column.

152

153

Parameters:

154

- column: Column name to calculate std

155

- ddof: Delta degrees of freedom

156

157

Returns:

158

Standard deviation expression

159

"""

160

161

def var(column: str, ddof: int = 1) -> Expr:

162

"""

163

Calculate variance of a column.

164

165

Parameters:

166

- column: Column name to calculate variance

167

- ddof: Delta degrees of freedom

168

169

Returns:

170

Variance expression

171

"""

172

173

def quantile(expr, quantile, interpolation="nearest") -> Expr:

174

"""

175

Calculate quantile of expression.

176

177

Parameters:

178

- expr: Expression to calculate quantile

179

- quantile: Quantile value (0-1)

180

- interpolation: Interpolation method

181

182

Returns:

183

Quantile expression

184

"""

185

```

186

187

### Horizontal Aggregation Functions

188

189

Functions for aggregating across columns (horizontally) rather than rows.

190

191

```python { .api }

192

def all_horizontal(*exprs) -> Expr:

193

"""

194

Check if all values are true across columns.

195

196

Parameters:

197

- exprs: Boolean expressions

198

199

Returns:

200

All-true expression

201

"""

202

203

def any_horizontal(*exprs) -> Expr:

204

"""

205

Check if any value is true across columns.

206

207

Parameters:

208

- exprs: Boolean expressions

209

210

Returns:

211

Any-true expression

212

"""

213

214

def sum_horizontal(*exprs) -> Expr:

215

"""

216

Sum values horizontally across columns.

217

218

Parameters:

219

- exprs: Numeric expressions

220

221

Returns:

222

Horizontal sum expression

223

"""

224

225

def mean_horizontal(*exprs) -> Expr:

226

"""

227

Calculate mean horizontally across columns.

228

229

Parameters:

230

- exprs: Numeric expressions

231

232

Returns:

233

Horizontal mean expression

234

"""

235

236

def max_horizontal(*exprs) -> Expr:

237

"""

238

Find maximum value horizontally across columns.

239

240

Parameters:

241

- exprs: Numeric expressions

242

243

Returns:

244

Horizontal max expression

245

"""

246

247

def min_horizontal(*exprs) -> Expr:

248

"""

249

Find minimum value horizontally across columns.

250

251

Parameters:

252

- exprs: Numeric expressions

253

254

Returns:

255

Horizontal min expression

256

"""

257

```

258

259

### Range Generation Functions

260

261

Functions for creating sequences and ranges of values.

262

263

```python { .api }

264

def arange(start, end, step=1, *, dtype=None, eager=False) -> Expr | Series:

265

"""

266

Create arithmetic range of values.

267

268

Parameters:

269

- start: Start value

270

- end: End value (exclusive)

271

- step: Step size

272

- dtype: Data type

273

- eager: Return Series if True, Expr if False

274

275

Returns:

276

Range expression or Series

277

"""

278

279

def int_range(start, end, step=1, *, dtype=None, eager=False) -> Expr | Series:

280

"""

281

Create integer range of values.

282

283

Parameters:

284

- start: Start value

285

- end: End value (exclusive)

286

- step: Step size

287

- dtype: Integer data type

288

- eager: Return Series if True, Expr if False

289

290

Returns:

291

Integer range expression or Series

292

"""

293

294

def int_ranges(start, end, step=1, *, dtype=None, eager=False) -> Expr | Series:

295

"""

296

Create multiple integer ranges.

297

298

Parameters:

299

- start: Start values (can be expression)

300

- end: End values (can be expression)

301

- step: Step size

302

- dtype: Integer data type

303

- eager: Return Series if True, Expr if False

304

305

Returns:

306

Multiple ranges expression or Series

307

"""

308

309

def linear_space(start, end, n, *, dtype=None, eager=False) -> Expr | Series:

310

"""

311

Create linearly spaced values.

312

313

Parameters:

314

- start: Start value

315

- end: End value (inclusive)

316

- n: Number of values

317

- dtype: Data type

318

- eager: Return Series if True, Expr if False

319

320

Returns:

321

Linear space expression or Series

322

"""

323

324

def linear_spaces(start, end, n, *, dtype=None, eager=False) -> Expr | Series:

325

"""

326

Create multiple linearly spaced ranges.

327

328

Parameters:

329

- start: Start values (can be expression)

330

- end: End values (can be expression)

331

- n: Number of values per range

332

- dtype: Data type

333

- eager: Return Series if True, Expr if False

334

335

Returns:

336

Multiple linear spaces expression or Series

337

"""

338

```

339

340

### Temporal Range Functions

341

342

Functions for creating date, datetime, and time ranges.

343

344

```python { .api }

345

def date_range(start, end, interval="1d", *, closed="both", eager=False) -> Expr | Series:

346

"""

347

Create date range.

348

349

Parameters:

350

- start: Start date

351

- end: End date

352

- interval: Date interval (e.g., "1d", "1w", "1mo")

353

- closed: Range bounds ("both", "left", "right", "none")

354

- eager: Return Series if True, Expr if False

355

356

Returns:

357

Date range expression or Series

358

"""

359

360

def date_ranges(start, end, interval="1d", *, closed="both", eager=False) -> Expr | Series:

361

"""

362

Create multiple date ranges.

363

364

Parameters:

365

- start: Start dates (can be expression)

366

- end: End dates (can be expression)

367

- interval: Date interval

368

- closed: Range bounds

369

- eager: Return Series if True, Expr if False

370

371

Returns:

372

Multiple date ranges expression or Series

373

"""

374

375

def datetime_range(start, end, interval="1h", *, closed="both", time_zone=None, eager=False) -> Expr | Series:

376

"""

377

Create datetime range.

378

379

Parameters:

380

- start: Start datetime

381

- end: End datetime

382

- interval: Datetime interval (e.g., "1h", "30m", "1d")

383

- closed: Range bounds

384

- time_zone: Timezone

385

- eager: Return Series if True, Expr if False

386

387

Returns:

388

Datetime range expression or Series

389

"""

390

391

def datetime_ranges(start, end, interval="1h", *, closed="both", time_zone=None, eager=False) -> Expr | Series:

392

"""

393

Create multiple datetime ranges.

394

395

Parameters:

396

- start: Start datetimes (can be expression)

397

- end: End datetimes (can be expression)

398

- interval: Datetime interval

399

- closed: Range bounds

400

- time_zone: Timezone

401

- eager: Return Series if True, Expr if False

402

403

Returns:

404

Multiple datetime ranges expression or Series

405

"""

406

407

def time_range(start, end, interval="1h", *, closed="both", eager=False) -> Expr | Series:

408

"""

409

Create time range.

410

411

Parameters:

412

- start: Start time

413

- end: End time

414

- interval: Time interval

415

- closed: Range bounds

416

- eager: Return Series if True, Expr if False

417

418

Returns:

419

Time range expression or Series

420

"""

421

422

def time_ranges(start, end, interval="1h", *, closed="both", eager=False) -> Expr | Series:

423

"""

424

Create multiple time ranges.

425

426

Parameters:

427

- start: Start times (can be expression)

428

- end: End times (can be expression)

429

- interval: Time interval

430

- closed: Range bounds

431

- eager: Return Series if True, Expr if False

432

433

Returns:

434

Multiple time ranges expression or Series

435

"""

436

```

437

438

### Datetime Construction Functions

439

440

Functions for creating date, datetime, and time values from components.

441

442

```python { .api }

443

def date(year, month, day) -> Expr:

444

"""

445

Create date from year, month, day components.

446

447

Parameters:

448

- year: Year expression or value

449

- month: Month expression or value (1-12)

450

- day: Day expression or value (1-31)

451

452

Returns:

453

Date expression

454

"""

455

456

def datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, *, time_unit="us", time_zone=None) -> Expr:

457

"""

458

Create datetime from components.

459

460

Parameters:

461

- year: Year expression or value

462

- month: Month expression or value (1-12)

463

- day: Day expression or value (1-31)

464

- hour: Hour expression or value (0-23)

465

- minute: Minute expression or value (0-59)

466

- second: Second expression or value (0-59)

467

- microsecond: Microsecond expression or value

468

- time_unit: Time precision ("ns", "us", "ms")

469

- time_zone: Timezone

470

471

Returns:

472

Datetime expression

473

"""

474

475

def time(hour=0, minute=0, second=0, microsecond=0) -> Expr:

476

"""

477

Create time from components.

478

479

Parameters:

480

- hour: Hour expression or value (0-23)

481

- minute: Minute expression or value (0-59)

482

- second: Second expression or value (0-59)

483

- microsecond: Microsecond expression or value

484

485

Returns:

486

Time expression

487

"""

488

489

def duration(*, weeks=None, days=None, hours=None, minutes=None, seconds=None, milliseconds=None, microseconds=None, nanoseconds=None, time_unit="us") -> Expr:

490

"""

491

Create duration from time components.

492

493

Parameters:

494

- weeks: Weeks expression or value

495

- days: Days expression or value

496

- hours: Hours expression or value

497

- minutes: Minutes expression or value

498

- seconds: Seconds expression or value

499

- milliseconds: Milliseconds expression or value

500

- microseconds: Microseconds expression or value

501

- nanoseconds: Nanoseconds expression or value

502

- time_unit: Time precision

503

504

Returns:

505

Duration expression

506

"""

507

508

def from_epoch(column, time_unit="s") -> Expr:

509

"""

510

Convert epoch timestamp to datetime.

511

512

Parameters:

513

- column: Column with epoch timestamps

514

- time_unit: Time unit of epoch ("s", "ms", "us", "ns")

515

516

Returns:

517

Datetime expression

518

"""

519

```

520

521

### Statistical Functions

522

523

Functions for statistical analysis and correlation calculations.

524

525

```python { .api }

526

def corr(a, b, *, method="pearson", ddof=1, propagate_nans=False) -> Expr:

527

"""

528

Calculate correlation coefficient between two expressions.

529

530

Parameters:

531

- a: First expression

532

- b: Second expression

533

- method: Correlation method ("pearson", "spearman")

534

- ddof: Delta degrees of freedom

535

- propagate_nans: Propagate NaN values

536

537

Returns:

538

Correlation expression

539

"""

540

541

def cov(a, b, *, ddof=1) -> Expr:

542

"""

543

Calculate covariance between two expressions.

544

545

Parameters:

546

- a: First expression

547

- b: Second expression

548

- ddof: Delta degrees of freedom

549

550

Returns:

551

Covariance expression

552

"""

553

554

def rolling_corr(a, b, window_size, *, min_periods=None, ddof=1) -> Expr:

555

"""

556

Calculate rolling correlation.

557

558

Parameters:

559

- a: First expression

560

- b: Second expression

561

- window_size: Rolling window size

562

- min_periods: Minimum periods for calculation

563

- ddof: Delta degrees of freedom

564

565

Returns:

566

Rolling correlation expression

567

"""

568

569

def rolling_cov(a, b, window_size, *, min_periods=None, ddof=1) -> Expr:

570

"""

571

Calculate rolling covariance.

572

573

Parameters:

574

- a: First expression

575

- b: Second expression

576

- window_size: Rolling window size

577

- min_periods: Minimum periods for calculation

578

- ddof: Delta degrees of freedom

579

580

Returns:

581

Rolling covariance expression

582

"""

583

584

def n_unique(expr) -> Expr:

585

"""

586

Count unique values in expression.

587

588

Parameters:

589

- expr: Expression to count unique values

590

591

Returns:

592

Unique count expression

593

"""

594

595

def approx_n_unique(expr) -> Expr:

596

"""

597

Approximate count of unique values using HyperLogLog.

598

599

Parameters:

600

- expr: Expression to count unique values

601

602

Returns:

603

Approximate unique count expression

604

"""

605

```

606

607

### Cumulative Functions

608

609

Functions for cumulative operations and running calculations.

610

611

```python { .api }

612

def cum_sum(expr, *, reverse=False) -> Expr:

613

"""

614

Calculate cumulative sum.

615

616

Parameters:

617

- expr: Expression to sum cumulatively

618

- reverse: Calculate in reverse order

619

620

Returns:

621

Cumulative sum expression

622

"""

623

624

def cum_sum_horizontal(*exprs) -> Expr:

625

"""

626

Calculate cumulative sum horizontally across columns.

627

628

Parameters:

629

- exprs: Expressions to sum cumulatively

630

631

Returns:

632

Horizontal cumulative sum expression

633

"""

634

635

def cum_count(expr, *, reverse=False) -> Expr:

636

"""

637

Calculate cumulative count.

638

639

Parameters:

640

- expr: Expression to count cumulatively

641

- reverse: Calculate in reverse order

642

643

Returns:

644

Cumulative count expression

645

"""

646

647

def cum_fold(acc, lambda_expr, exprs, *, include_init=False) -> Expr:

648

"""

649

Cumulative fold operation with custom function.

650

651

Parameters:

652

- acc: Initial accumulator value

653

- lambda_expr: Fold function (takes acc, value)

654

- exprs: Expressions to fold

655

- include_init: Include initial value in result

656

657

Returns:

658

Cumulative fold expression

659

"""

660

661

def cum_reduce(lambda_expr, exprs) -> Expr:

662

"""

663

Cumulative reduce operation.

664

665

Parameters:

666

- lambda_expr: Reduce function

667

- exprs: Expressions to reduce

668

669

Returns:

670

Cumulative reduce expression

671

"""

672

```

673

674

### Higher-Order Functions

675

676

Functions for advanced operations with custom lambda functions.

677

678

```python { .api }

679

def fold(acc, lambda_expr, exprs) -> Expr:

680

"""

681

Fold operation with custom function.

682

683

Parameters:

684

- acc: Initial accumulator value

685

- lambda_expr: Fold function (takes acc, value)

686

- exprs: Expressions to fold

687

688

Returns:

689

Fold expression

690

"""

691

692

def reduce(lambda_expr, exprs) -> Expr:

693

"""

694

Reduce operation with custom function.

695

696

Parameters:

697

- lambda_expr: Reduce function (takes two values)

698

- exprs: Expressions to reduce

699

700

Returns:

701

Reduce expression

702

"""

703

704

def map_batches(expr, function, return_dtype=None, *, agg_list=False) -> Expr:

705

"""

706

Apply function to batches of data.

707

708

Parameters:

709

- expr: Expression to map over

710

- function: Function to apply to each batch

711

- return_dtype: Return data type

712

- agg_list: Aggregate results into list

713

714

Returns:

715

Map batches expression

716

"""

717

718

def map_groups(expr, function, return_dtype=None) -> Expr:

719

"""

720

Apply function to groups of data.

721

722

Parameters:

723

- expr: Expression to map over

724

- function: Function to apply to each group

725

- return_dtype: Return data type

726

727

Returns:

728

Map groups expression

729

"""

730

```

731

732

### Conditional Functions

733

734

Functions for conditional logic and branching.

735

736

```python { .api }

737

def when(condition) -> When:

738

"""

739

Start conditional expression chain.

740

741

Parameters:

742

- condition: Boolean condition expression

743

744

Returns:

745

When object for chaining

746

"""

747

748

def coalesce(*exprs) -> Expr:

749

"""

750

Return first non-null value from expressions.

751

752

Parameters:

753

- exprs: Expressions to coalesce

754

755

Returns:

756

Coalesced expression

757

"""

758

759

class When:

760

def then(self, expr) -> Then:

761

"""

762

Specify value when condition is true.

763

764

Parameters:

765

- expr: Expression or value to return

766

767

Returns:

768

Then object for chaining

769

"""

770

771

class Then:

772

def when(self, condition) -> When:

773

"""

774

Add another condition.

775

776

Parameters:

777

- condition: Boolean condition expression

778

779

Returns:

780

When object for chaining

781

"""

782

783

def otherwise(self, expr) -> Expr:

784

"""

785

Specify default value.

786

787

Parameters:

788

- expr: Default expression or value

789

790

Returns:

791

Complete conditional expression

792

"""

793

```

794

795

### Utility Functions

796

797

Miscellaneous utility functions for various operations.

798

799

```python { .api }

800

def concat(*dfs, *, how="vertical", parallel=True) -> DataFrame | LazyFrame:

801

"""

802

Concatenate DataFrames or LazyFrames.

803

804

Parameters:

805

- dfs: DataFrames or LazyFrames to concatenate

806

- how: Concatenation method ("vertical", "horizontal", "diagonal")

807

- parallel: Use parallel execution

808

809

Returns:

810

Concatenated DataFrame or LazyFrame

811

"""

812

813

def concat_str(exprs, *, separator="", ignore_nulls=False) -> Expr:

814

"""

815

Concatenate string expressions.

816

817

Parameters:

818

- exprs: String expressions to concatenate

819

- separator: String separator

820

- ignore_nulls: Skip null values

821

822

Returns:

823

Concatenated string expression

824

"""

825

826

def concat_list(exprs) -> Expr:

827

"""

828

Concatenate expressions into list.

829

830

Parameters:

831

- exprs: Expressions to concatenate into list

832

833

Returns:

834

List expression

835

"""

836

837

def concat_arr(exprs) -> Expr:

838

"""

839

Concatenate expressions into array.

840

841

Parameters:

842

- exprs: Expressions to concatenate into array

843

844

Returns:

845

Array expression

846

"""

847

848

def format(format_str, *args) -> Expr:

849

"""

850

Format string with expressions.

851

852

Parameters:

853

- format_str: Format string with {} placeholders

854

- args: Expressions to substitute

855

856

Returns:

857

Formatted string expression

858

"""

859

860

def escape_regex(expr) -> Expr:

861

"""

862

Escape regex special characters in string.

863

864

Parameters:

865

- expr: String expression to escape

866

867

Returns:

868

Escaped string expression

869

"""

870

871

def dtype_of(expr) -> DataType:

872

"""

873

Get data type of expression.

874

875

Parameters:

876

- expr: Expression to inspect

877

878

Returns:

879

Data type

880

"""

881

882

def set_random_seed(seed) -> None:

883

"""

884

Set global random seed.

885

886

Parameters:

887

- seed: Random seed value

888

"""

889

```

890

891

## Usage Examples

892

893

### Basic Function Usage

894

895

```python

896

import polars as pl

897

898

# Construction functions

899

df = pl.DataFrame({

900

"a": [1, 2, 3],

901

"b": [4, 5, 6],

902

"c": ["x", "y", "z"]

903

})

904

905

result = df.select([

906

pl.col("a"),

907

pl.lit(10).alias("constant"),

908

pl.struct(["a", "b"]).alias("struct_col")

909

])

910

```

911

912

### Aggregation Functions

913

914

```python

915

# Various aggregations

916

result = df.select([

917

pl.col("a").sum().alias("sum_a"),

918

pl.col("b").mean().alias("mean_b"),

919

pl.max_horizontal("a", "b").alias("row_max"),

920

pl.sum_horizontal("a", "b").alias("row_sum")

921

])

922

923

# Group by aggregations

924

grouped = df.group_by("c").agg([

925

pl.col("a").sum(),

926

pl.col("b").mean(),

927

pl.col("a").std().alias("a_std")

928

])

929

```

930

931

### Range Generation

932

933

```python

934

# Create ranges

935

ranges_df = pl.DataFrame({

936

"int_range": pl.int_range(0, 10, 2, eager=True),

937

"date_range": pl.date_range("2023-01-01", "2023-01-10", "1d", eager=True)

938

})

939

940

# Multiple ranges from DataFrame

941

df = pl.DataFrame({

942

"start": [1, 5, 10],

943

"end": [5, 10, 15]

944

})

945

946

result = df.with_columns([

947

pl.int_ranges("start", "end").alias("ranges")

948

])

949

```

950

951

### Statistical Operations

952

953

```python

954

df = pl.DataFrame({

955

"x": [1, 2, 3, 4, 5],

956

"y": [2, 4, 6, 8, 10]

957

})

958

959

# Statistical functions

960

stats = df.select([

961

pl.corr("x", "y").alias("correlation"),

962

pl.cov("x", "y").alias("covariance"),

963

pl.col("x").std().alias("x_std"),

964

pl.col("y").var().alias("y_var")

965

])

966

967

# Rolling statistics

968

windowed = df.with_columns([

969

pl.rolling_corr("x", "y", window_size=3).alias("rolling_corr"),

970

pl.col("x").rolling_mean(3).alias("rolling_mean")

971

])

972

```

973

974

### Conditional Logic

975

976

```python

977

# Complex conditional expressions

978

result = df.with_columns([

979

pl.when(pl.col("x") > 3)

980

.then(pl.lit("high"))

981

.when(pl.col("x") > 1)

982

.then(pl.lit("medium"))

983

.otherwise(pl.lit("low"))

984

.alias("category"),

985

986

pl.coalesce([pl.col("a"), pl.col("b"), pl.lit(0)]).alias("first_non_null")

987

])

988

```

989

990

### Higher-Order Functions

991

992

```python

993

# Custom fold operation

994

result = df.select([

995

pl.fold(

996

acc=pl.lit(0),

997

lambda_expr=lambda acc, x: acc + x,

998

exprs=[pl.col("a"), pl.col("b")]

999

).alias("custom_sum")

1000

])

1001

1002

# Map batches with custom function

1003

def custom_transform(series):

1004

return series * 2 + 1

1005

1006

result = df.with_columns([

1007

pl.col("a").map_batches(custom_transform).alias("transformed")

1008

])

1009

```

1010

1011

### String and Array Operations

1012

1013

```python

1014

# String concatenation and formatting

1015

df = pl.DataFrame({

1016

"first": ["John", "Jane"],

1017

"last": ["Doe", "Smith"],

1018

"age": [30, 25]

1019

})

1020

1021

result = df.with_columns([

1022

pl.concat_str([pl.col("first"), pl.col("last")], separator=" ").alias("full_name"),

1023

pl.format("Name: {}, Age: {}", pl.col("first"), pl.col("age")).alias("formatted")

1024

])

1025

1026

# Array concatenation

1027

df = pl.DataFrame({

1028

"list1": [[1, 2], [3, 4]],

1029

"list2": [[5, 6], [7, 8]]

1030

})

1031

1032

result = df.with_columns([

1033

pl.concat_list([pl.col("list1"), pl.col("list2")]).alias("combined")

1034

])

1035

```