Returns the number of non-overlapping occurrences of substring sub in the range [start, end). Optional arguments start and end are interpreted as in slice notation. Example: >>> import pathway as pw >>> table = pw.debug.table_from_markdown( ... '''
(
self,
sub: expr.ColumnExpression | str,
start: expr.ColumnExpression | int | None = None,
end: expr.ColumnExpression | int | None = None,
)
| 471 | ) |
| 472 | |
| 473 | def count( |
| 474 | self, |
| 475 | sub: expr.ColumnExpression | str, |
| 476 | start: expr.ColumnExpression | int | None = None, |
| 477 | end: expr.ColumnExpression | int | None = None, |
| 478 | ) -> expr.ColumnExpression: |
| 479 | """Returns the number of non-overlapping occurrences of substring sub in the range [start, end). |
| 480 | Optional arguments start and end are interpreted as in slice notation. |
| 481 | |
| 482 | |
| 483 | Example: |
| 484 | |
| 485 | >>> import pathway as pw |
| 486 | >>> table = pw.debug.table_from_markdown( |
| 487 | ... ''' |
| 488 | ... | name |
| 489 | ... 1 | Alice |
| 490 | ... 2 | Hello |
| 491 | ... 3 | World |
| 492 | ... 4 | Zoo |
| 493 | ... ''' |
| 494 | ... ) |
| 495 | >>> table += table.select(count=table.name.str.count("o")) |
| 496 | >>> pw.debug.compute_and_print(table, include_id=False) |
| 497 | name | count |
| 498 | Alice | 0 |
| 499 | Hello | 1 |
| 500 | World | 1 |
| 501 | Zoo | 2 |
| 502 | """ |
| 503 | |
| 504 | return expr.MethodCallExpression( |
| 505 | ( |
| 506 | ( |
| 507 | ( |
| 508 | dt.STR, |
| 509 | dt.STR, |
| 510 | dt.Optional(dt.INT), |
| 511 | dt.Optional(dt.INT), |
| 512 | ), |
| 513 | dt.INT, |
| 514 | lambda *args: api.Expression.apply( |
| 515 | str.count, *args, dtype=dt.INT.to_engine() |
| 516 | ), |
| 517 | ), |
| 518 | ), |
| 519 | "str.count", |
| 520 | self._expression, |
| 521 | sub, |
| 522 | start, |
| 523 | end, |
| 524 | ) |
| 525 | |
| 526 | def find( |
| 527 | self, |