Expressions API

class pw.DateTimeNamespace(expression)

A module containing methods related to DateTimes. They can be called using a dt attribute of an expression.

Typical use:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         t1
   1 | 2023-05-15T14:13:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_days = table_with_datetime.select(day=table_with_datetime.t1.dt.day())

add_duration_in_timezone(duration, timezone)

Adds Duration to DateTime taking into account time zone.
  • Parameters
    • duration (Union[ColumnExpression, Timedelta]) – Duration to be added to DateTime.
    • timezone (Union[ColumnExpression, str]) – The time zone to perform addition in.
  • Returns
    DateTimeNaive or DateTimeUtc depending on the type of an object the method was called on

Example:

import pathway as pw
import datetime
t1 = pw.debug.table_from_markdown(
    '''
     |        date
   1 | 2023-03-26T01:23:00
   2 | 2023-03-27T01:23:00
   3 | 2023-10-29T01:23:00
   4 | 2023-10-30T01:23:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
t2 = t1.select(date=pw.this.date.dt.strptime(fmt=fmt))
t3 = t2.with_columns(
    new_date=pw.this.date.dt.add_duration_in_timezone(
        datetime.timedelta(hours=2), timezone="Europe/Warsaw"
    ),
)
pw.debug.compute_and_print(t3, include_id=False)
date                | new_date
2023-03-26 01:23:00 | 2023-03-26 04:23:00
2023-03-27 01:23:00 | 2023-03-27 03:23:00
2023-10-29 01:23:00 | 2023-10-29 02:23:00
2023-10-30 01:23:00 | 2023-10-30 03:23:00

day()

Extracts day from a DateTime.
  • Returns
    Day as int. 1 <= day <= 31 (depending on a month)

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1974-03-12T00:00:00
   2 | 2023-03-25T12:00:00
   3 | 2023-05-15T14:13:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_days = table_with_datetime.select(day=table_with_datetime.t1.dt.day())
pw.debug.compute_and_print(table_with_days, include_id=False)
day
12
15
25

days()

The total number of days in a Duration.
  • Returns
    Days as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         t1          |         t2
   0 | 2023-03-15T00:00:00 | 2023-05-15T10:13:23
   1 | 2023-04-15T00:00:00 | 2023-05-15T10:00:00
   2 | 2023-05-01T10:00:00 | 2023-05-15T10:00:00
   3 | 2023-05-15T10:00:00 | 2023-05-15T09:00:00
   4 | 2023-05-15T10:00:00 | 2023-05-15T11:00:00
   5 | 2023-05-16T12:13:00 | 2023-05-15T10:00:00
   6 | 2024-05-15T14:13:23 | 2023-05-15T10:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_days = table_with_diff.select(days=pw.this["diff"].dt.days())
pw.debug.compute_and_print(table_with_days, include_id=False)
days
-61
-30
-14
0
0
1
366

floor(duration)

Truncates DateTime to precision specified by duration argument.
  • Parameters
    duration (Union[ColumnExpression, Timedelta]) – truncation precision
  • Returns
    DateTimeNaive or DateTimeUtc depending on the type of an object the method was called on

Examples:

import pathway as pw
import datetime
t1 = pw.debug.table_from_markdown(
    '''
     |         date
   1 | 2023-05-15T12:23:12
   2 | 2023-05-15T12:33:21
   3 | 2023-05-15T13:20:35
   4 | 2023-05-15T13:51:41
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
t2 = t1.select(date=pw.this.date.dt.strptime(fmt=fmt))
res = t2.with_columns(
    truncated_to_hours=pw.this.date.dt.floor(datetime.timedelta(hours=1)),
    truncated_to_10_min=pw.this.date.dt.floor(datetime.timedelta(minutes=10)),
    truncated_to_15_s=pw.this.date.dt.floor(datetime.timedelta(seconds=15)),
)
pw.debug.compute_and_print(res, include_id=False)
date                | truncated_to_hours  | truncated_to_10_min | truncated_to_15_s
2023-05-15 12:23:12 | 2023-05-15 12:00:00 | 2023-05-15 12:20:00 | 2023-05-15 12:23:00
2023-05-15 12:33:21 | 2023-05-15 12:00:00 | 2023-05-15 12:30:00 | 2023-05-15 12:33:15
2023-05-15 13:20:35 | 2023-05-15 13:00:00 | 2023-05-15 13:20:00 | 2023-05-15 13:20:30
2023-05-15 13:51:41 | 2023-05-15 13:00:00 | 2023-05-15 13:50:00 | 2023-05-15 13:51:30

from_timestamp(unit)

Converts timestamp represented as an int to DateTime.
  • Parameters
    • timestamp – value to be converted to DateTime
    • unit (str) – unit of a timestamp. It has to be one of ‘s’, ‘ms’, ‘us’, ‘ns’
  • Returns
    DateTime

Example:

import pathway as pw
fmt = "%Y-%m-%dT%H:%M:%S"
t1 = pw.debug.table_from_markdown(
    '''
  | timestamp
1 |    10
2 | 1685969950
'''
)
t2 = t1.select(date=pw.this.timestamp.dt.from_timestamp(unit="s"))
pw.debug.compute_and_print(t2, include_id=False)
date
1970-01-01 00:00:10
2023-06-05 12:59:10

hour()

Extracts hour from a DateTime.
  • Returns
    Hour as int. 0 <= hour < 24

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T00:00:00
   2 | 2023-05-15T12:00:00
   3 | 2023-05-15T14:13:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_hours = table_with_datetime.select(hour=table_with_datetime.t1.dt.hour())
pw.debug.compute_and_print(table_with_hours, include_id=False)
hour
0
12
14

hours()

The total number of hours in a Duration.
  • Returns
    Hours as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         t1          |         t2
   0 | 2023-05-15T00:00:00 | 2023-05-15T10:13:23
   1 | 2023-05-15T00:00:00 | 2023-05-15T10:00:00
   2 | 2023-05-15T10:00:00 | 2023-05-15T10:00:00
   3 | 2023-05-15T10:00:23 | 2023-05-15T10:00:00
   4 | 2023-05-15T12:13:00 | 2023-05-15T10:00:00
   5 | 2023-05-15T14:13:23 | 2023-05-15T10:00:00
   6 | 2023-05-16T10:13:23 | 2023-05-15T10:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_hours = table_with_diff.select(hours=pw.this["diff"].dt.hours())
pw.debug.compute_and_print(table_with_hours, include_id=False)
hours
-10
-10
0
0
2
4
24

microsecond()

Extracts microseconds from a DateTime.
  • Returns
    Microsecond as int. 0 <= microsecond < 1_000_000

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.000012000
   3 | 2023-05-15T10:13:00.123456789
   4 | 2023-05-15T10:13:23.123456789
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f"))
table_with_microseconds = table_with_datetime.select(
    microsecond=table_with_datetime.t1.dt.microsecond()
)
pw.debug.compute_and_print(table_with_microseconds, include_id=False)
microsecond
0
12
123456
123456

microseconds()

The total number of microseconds in a Duration.
  • Returns
    Microseconds as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1              |               t2
   0 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:23.123456789
   1 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.000012000 | 2023-05-15T10:13:00.000000000
   3 | 2023-05-15T10:13:00.123456789 | 2023-05-15T10:13:00.000000000
   4 | 2023-05-15T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
   5 | 2023-05-16T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
'''
)
fmt = "%Y-%m-%dT%H:%M:%S.%f"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_microseconds = table_with_diff.select(
    microseconds=pw.this["diff"].dt.microseconds()
)
pw.debug.compute_and_print(table_with_microseconds, include_id=False)
microseconds
-23123456
0
12
123456
23123456
86423123456

millisecond()

Extracts milliseconds from a DateTime.
  • Returns
    Millisecond as int. 0 <= millisecond < 1_000

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.012000000
   3 | 2023-05-15T10:13:00.123456789
   4 | 2023-05-15T10:13:23.123456789
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f"))
table_with_milliseconds = table_with_datetime.select(
    millisecond=table_with_datetime.t1.dt.millisecond()
)
pw.debug.compute_and_print(table_with_milliseconds, include_id=False)
millisecond
0
12
123
123

milliseconds()

The total number of milliseconds in a Duration.
  • Returns
    Milliseconds as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1              |               t2
   0 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:23.123456789
   1 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.012000000 | 2023-05-15T10:13:00.000000000
   3 | 2023-05-15T10:13:00.123456789 | 2023-05-15T10:13:00.000000000
   4 | 2023-05-15T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
   5 | 2023-05-16T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
'''
)
fmt = "%Y-%m-%dT%H:%M:%S.%f"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_milliseconds = table_with_diff.select(
    milliseconds=pw.this["diff"].dt.milliseconds()
)
pw.debug.compute_and_print(table_with_milliseconds, include_id=False)
milliseconds
-23123
0
12
123
23123
86423123

minute()

Extracts minute from a DateTime.
  • Returns
    Minute as int. 0 <= minute < 60

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T10:00:00
   2 | 2023-05-15T10:00:23
   3 | 2023-05-15T10:13:00
   4 | 2023-05-15T10:13:23
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_minutes = table_with_datetime.select(
    minute=table_with_datetime.t1.dt.minute()
)
pw.debug.compute_and_print(table_with_minutes, include_id=False)
minute
0
0
13
13

minutes()

The total number of minutes in a Duration.
  • Returns
    Minutes as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         t1          |         t2
   0 | 2023-05-15T10:00:00 | 2023-05-15T10:13:23
   1 | 2023-05-15T10:00:00 | 2023-05-15T10:00:00
   2 | 2023-05-15T10:00:23 | 2023-05-15T10:00:00
   3 | 2023-05-15T10:13:00 | 2023-05-15T10:00:00
   4 | 2023-05-15T10:13:23 | 2023-05-15T10:00:00
   5 | 2023-05-16T10:13:23 | 2023-05-15T10:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_minutes = table_with_diff.select(minutes=pw.this["diff"].dt.minutes())
pw.debug.compute_and_print(table_with_minutes, include_id=False)
minutes
-13
0
0
13
13
1453

month()

Extracts month from a DateTime.
  • Returns
    Month as int. 1 <= month <= 12

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1974-03-12T00:00:00
   2 | 2023-03-25T12:00:00
   3 | 2023-05-15T14:13:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_months = table_with_datetime.select(month=table_with_datetime.t1.dt.month())
pw.debug.compute_and_print(table_with_months, include_id=False)
month
3
3
5

nanosecond()

Extracts nanoseconds from a DateTime.
  • Returns
    Nanosecond as int. 0 <= nanosecond < 1_000_000_000

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.000000012
   3 | 2023-05-15T10:13:00.123456789
   4 | 2023-05-15T10:13:23.123456789
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f"))
table_with_nanoseconds = table_with_datetime.select(
    nanosecond=table_with_datetime.t1.dt.nanosecond()
)
pw.debug.compute_and_print(table_with_nanoseconds, include_id=False)
nanosecond
0
12
123456789
123456789

nanoseconds()

The total number of nanoseconds in a Duration.
  • Returns
    Nanoseconds as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1              |               t2
   0 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:23.123456789
   1 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.000000012 | 2023-05-15T10:13:00.000000000
   3 | 2023-05-15T10:13:00.123456789 | 2023-05-15T10:13:00.000000000
   4 | 2023-05-15T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
   5 | 2023-05-16T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
'''
)
fmt = "%Y-%m-%dT%H:%M:%S.%f"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_nanoseconds = table_with_diff.select(
    nanoseconds=pw.this["diff"].dt.nanoseconds()
)
pw.debug.compute_and_print(table_with_nanoseconds, include_id=False)
nanoseconds
-23123456789
0
12
123456789
23123456789
86423123456789

round(duration)

Rounds DateTime to precision specified by duration argument.
  • Parameters
    duration (Union[ColumnExpression, Timedelta]) – rounding precision
  • Returns
    DateTimeNaive or DateTimeUtc depending on the type of an object the method was called on

Examples:

import pathway as pw
import datetime
t1 = pw.debug.table_from_markdown(
    '''
     |         date
   1 | 2023-05-15T12:23:12
   2 | 2023-05-15T12:33:21
   3 | 2023-05-15T13:20:35
   4 | 2023-05-15T13:51:41
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
t2 = t1.select(date=pw.this.date.dt.strptime(fmt=fmt))
res = t2.with_columns(
    rounded_to_hours=pw.this.date.dt.round(datetime.timedelta(hours=1)),
    rounded_to_10_min=pw.this.date.dt.round(datetime.timedelta(minutes=10)),
    rounded_to_15_s=pw.this.date.dt.round(datetime.timedelta(seconds=15)),
)
pw.debug.compute_and_print(res, include_id=False)
date                | rounded_to_hours    | rounded_to_10_min   | rounded_to_15_s
2023-05-15 12:23:12 | 2023-05-15 12:00:00 | 2023-05-15 12:20:00 | 2023-05-15 12:23:15
2023-05-15 12:33:21 | 2023-05-15 13:00:00 | 2023-05-15 12:30:00 | 2023-05-15 12:33:15
2023-05-15 13:20:35 | 2023-05-15 13:00:00 | 2023-05-15 13:20:00 | 2023-05-15 13:20:30
2023-05-15 13:51:41 | 2023-05-15 14:00:00 | 2023-05-15 13:50:00 | 2023-05-15 13:51:45

second()

Extracts seconds from a DateTime.
  • Returns
    Second as int. 0 <= second < 60

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.123456789
   3 | 2023-05-15T10:13:23.000000000
   4 | 2023-05-15T10:13:23.123456789
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f"))
table_with_seconds = table_with_datetime.select(
    second=table_with_datetime.t1.dt.second()
)
pw.debug.compute_and_print(table_with_seconds, include_id=False)
second
0
0
23
23

seconds()

The total number of seconds in a Duration.
  • Returns
    Seconds as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1              |               t2
   0 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:23.123456789
   1 | 2023-05-15T10:13:00.000000000 | 2023-05-15T10:13:00.000000000
   2 | 2023-05-15T10:13:00.123456789 | 2023-05-15T10:13:00.000000000
   3 | 2023-05-15T10:13:23.000000000 | 2023-05-15T10:13:00.000000000
   4 | 2023-05-15T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
   5 | 2023-05-16T10:13:23.123456789 | 2023-05-15T10:13:00.000000000
'''
)
fmt = "%Y-%m-%dT%H:%M:%S.%f"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_seconds = table_with_diff.select(seconds=pw.this["diff"].dt.seconds())
pw.debug.compute_and_print(table_with_seconds, include_id=False)
seconds
-23
0
0
23
23
86423

strftime(fmt)

Converts a DateTime to a string.
  • Parameters
    fmt (Union[ColumnExpression, str]) – Format string. We use the specifiers of chrono library. In most cases they are identical to standard python specifiers in strftime .
  • Returns
    str

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1970-02-03T10:13:00
   2 | 2023-03-25T10:13:00
   3 | 2023-03-26T12:13:00
   4 | 2023-05-15T14:13:23
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_with_datetime = table.select(t1=pw.this.t1.dt.strptime(fmt=fmt))
table_formatted = table_with_datetime.select(
    date=pw.this.t1.dt.strftime("%d.%m.%Y"),
    full_date=pw.this.t1.dt.strftime("%B %d, %Y"),
    time_24=pw.this.t1.dt.strftime("%H:%M:%S"),
    time_12=pw.this.t1.dt.strftime("%I:%M:%S %p"),
)
pw.debug.compute_and_print(table_formatted, include_id=False)
date       | full_date         | time_24  | time_12
03.02.1970 | February 03, 1970 | 10:13:00 | 10:13:00 AM
15.05.2023 | May 15, 2023      | 14:13:23 | 02:13:23 PM
25.03.2023 | March 25, 2023    | 10:13:00 | 10:13:00 AM
26.03.2023 | March 26, 2023    | 12:13:00 | 12:13:00 PM

strptime(fmt, contains_timezone=None)

Converts a string to a DateTime. If the string contains a timezone and a %z specifier is used, timezone-aware DateTime is created. Then the timezone is converted to a server timezone (see examples). If the string contains no timezone, a naive (not aware of timezone) DateTime is created.
  • Parameters
    fmt (Union[ColumnExpression, str]) – Format string. We use the specifiers of chrono library. In most cases they are identical to standard python specifiers in strptime . contains_timezone: If fmt is not a single string (the same for all objects) but a ColumnExpression, you need to set this parameter so that the function can determine if the return type is DateTimeNaive (contains_timezone = False) or DateTimeUtc (contains_timezone = True).
  • Returns
    DateTime

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1970-02-03T10:13:00.000000000
   2 | 2023-03-25T10:13:00.000000012
   3 | 2023-03-26T12:13:00.123456789
   4 | 2023-05-15T14:13:23.123456789
'''
)
fmt = "%Y-%m-%dT%H:%M:%S.%f"
table_with_datetime = table.select(t1=table.t1.dt.strptime(fmt=fmt))
pw.debug.compute_and_print(table_with_datetime, include_id=False)
t1
1970-02-03 10:13:00
2023-03-25 10:13:00.000000012
2023-03-26 12:13:00.123456789
2023-05-15 14:13:23.123456789

table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 03.02.1970T10:13:00.000000000
   2 | 25.03.2023T10:13:00.000000012
   3 | 26.03.2023T12:13:00.123456789
   4 | 15.05.2023T14:13:23.123456789
'''
)
fmt = "%d.%m.%YT%H:%M:%S.%f"
table_with_datetime = table.select(t1=table.t1.dt.strptime(fmt=fmt))
pw.debug.compute_and_print(table_with_datetime, include_id=False)
t1
1970-02-03 10:13:00
2023-03-25 10:13:00.000000012
2023-03-26 12:13:00.123456789
2023-05-15 14:13:23.123456789

table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1970-02-03T10:13:00-02:00
   2 | 2023-03-25T10:13:00+00:00
   3 | 2023-03-26T12:13:00-01:00
   4 | 2023-05-15T14:13:23+00:30
'''
)
fmt = "%Y-%m-%dT%H:%M:%S%z"
table_with_datetime = table.select(t1=table.t1.dt.strptime(fmt=fmt))
pw.debug.compute_and_print(table_with_datetime, include_id=False)
t1
1970-02-03 12:13:00+00:00
2023-03-25 10:13:00+00:00
2023-03-26 13:13:00+00:00
2023-05-15 13:43:23+00:00

subtract_date_time_in_timezone(date_time, timezone)

Subtracts two DateTimeNaives taking into account time zone.
  • Parameters
    • date_time (Union[ColumnExpression, Timestamp]) – DateTimeNaive to be subtracted from self.
    • timezone (Union[ColumnExpression, str]) – The time zone to perform subtraction in.
  • Returns
    Duration

Example:

import pathway as pw
t1 = pw.debug.table_from_markdown(
    '''
     |        date1        |        date2
   1 | 2023-03-26T03:20:00 | 2023-03-26T01:20:00
   2 | 2023-03-27T03:20:00 | 2023-03-27T01:20:00
   3 | 2023-10-29T03:20:00 | 2023-10-29T01:20:00
   4 | 2023-10-30T03:20:00 | 2023-10-30T01:20:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
t2 = t1.select(
    date1=pw.this.date1.dt.strptime(fmt=fmt), date2=pw.this.date2.dt.strptime(fmt=fmt)
)
t3 = t2.with_columns(
    diff=pw.this.date1.dt.subtract_date_time_in_timezone(
        pw.this.date2, timezone="Europe/Warsaw"
    ),
)
pw.debug.compute_and_print(t3, include_id=False)
date1               | date2               | diff
2023-03-26 03:20:00 | 2023-03-26 01:20:00 | 0 days 01:00:00
2023-03-27 03:20:00 | 2023-03-27 01:20:00 | 0 days 02:00:00
2023-10-29 03:20:00 | 2023-10-29 01:20:00 | 0 days 03:00:00
2023-10-30 03:20:00 | 2023-10-30 01:20:00 | 0 days 02:00:00

subtract_duration_in_timezone(duration, timezone)

Subtracts Duration from DateTime taking into account time zone.
  • Parameters
    • duration (Union[ColumnExpression, Timedelta]) – Duration to be subtracted from DateTime.
    • timezone (Union[ColumnExpression, str]) – The time zone to perform subtraction in.
  • Returns
    DateTimeNaive or DateTimeUtc depending on the type of an object the method was called on

Example:

import pathway as pw
import datetime
t1 = pw.debug.table_from_markdown(
    '''
     |        date
   1 | 2023-03-26T03:23:00
   2 | 2023-03-27T03:23:00
   3 | 2023-10-29T03:23:00
   4 | 2023-10-30T03:23:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
t2 = t1.select(date=pw.this.date.dt.strptime(fmt=fmt))
t3 = t2.with_columns(
    new_date=pw.this.date.dt.subtract_duration_in_timezone(
        datetime.timedelta(hours=2), timezone="Europe/Warsaw"
    ),
)
pw.debug.compute_and_print(t3, include_id=False)
date                | new_date
2023-03-26 03:23:00 | 2023-03-26 00:23:00
2023-03-27 03:23:00 | 2023-03-27 01:23:00
2023-10-29 03:23:00 | 2023-10-29 02:23:00
2023-10-30 03:23:00 | 2023-10-30 01:23:00

timestamp()

Returns a number of nanoseconds from 1970-01-01 for naive DateTime and from 1970-01-01 UTC for timezone-aware datetime.
  • Returns
    Timestamp as int.

Examples:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   0 | 1969-01-01T00:00:00.000000000
   1 | 1970-01-01T00:00:00.000000000
   2 | 2023-01-01T00:00:00.000000000
   3 | 2023-03-25T00:00:00.000000000
   4 | 2023-03-25T13:45:26.000000000
   5 | 2023-03-25T13:45:26.987654321
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f"))
table_with_timestamp = table_with_datetime.select(
    timestamp=table_with_datetime.t1.dt.timestamp()
)
pw.debug.compute_and_print(table_with_timestamp, include_id=False)
timestamp
-31536000000000000
0
1672531200000000000
1679702400000000000
1679751926000000000
1679751926987654321

table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1969-01-01T00:00:00.000000000+00:00
   2 | 1970-01-01T00:00:00.000000000+00:00
   3 | 1970-01-01T00:00:00.000000000+02:00
   4 | 1970-01-01T00:00:00.000000000-03:00
   5 | 2023-01-01T00:00:00.000000000+01:00
   6 | 2023-03-25T00:00:00.000000000+01:00
   7 | 2023-03-25T13:45:26.000000000+01:00
   8 | 2023-03-25T13:45:26.987654321+01:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S.%f%z"))
table_with_timestamp = table_with_datetime.select(
    timestamp=table_with_datetime.t1.dt.timestamp()
)
pw.debug.compute_and_print(table_with_timestamp, include_id=False)
timestamp
-31536000000000000
-7200000000000
0
10800000000000
1672527600000000000
1679698800000000000
1679748326000000000
1679748326987654321

to_naive_in_timezone(timezone)

Converts DateTimeUtc to time zone specified as timezone argument.
  • Parameters
    timezone (Union[ColumnExpression, str]) – The time zone to convert to.
  • Returns
    DateTimeNaive

Examples:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |        date_utc
   1 | 2023-03-26T00:59:00+00:00
   2 | 2023-03-26T01:00:00+00:00
   3 | 2023-03-27T00:59:00+00:00
   4 | 2023-03-27T01:00:00+00:00
   5 | 2023-10-28T23:59:00+00:00
   6 | 2023-10-29T00:00:00+00:00
   7 | 2023-10-29T00:30:00+00:00
   8 | 2023-10-29T01:00:00+00:00
   9 | 2023-10-29T01:30:00+00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S%z"
table_utc = table.select(date_utc=pw.this.date_utc.dt.strptime(fmt=fmt))
table_local = table_utc.with_columns(
    date=pw.this.date_utc.dt.to_naive_in_timezone(timezone="Europe/Warsaw"),
)
pw.debug.compute_and_print(table_local, include_id=False)
date_utc                  | date
2023-03-26 00:59:00+00:00 | 2023-03-26 01:59:00
2023-03-26 01:00:00+00:00 | 2023-03-26 03:00:00
2023-03-27 00:59:00+00:00 | 2023-03-27 02:59:00
2023-03-27 01:00:00+00:00 | 2023-03-27 03:00:00
2023-10-28 23:59:00+00:00 | 2023-10-29 01:59:00
2023-10-29 00:00:00+00:00 | 2023-10-29 02:00:00
2023-10-29 00:30:00+00:00 | 2023-10-29 02:30:00
2023-10-29 01:00:00+00:00 | 2023-10-29 02:00:00
2023-10-29 01:30:00+00:00 | 2023-10-29 02:30:00

table = pw.debug.table_from_markdown(
    '''
     |        date_utc
   1 | 2023-03-12T09:59:00+00:00
   2 | 2023-03-12T10:00:00+00:00
   3 | 2023-03-13T09:59:00+00:00
   4 | 2023-03-13T10:00:00+00:00
   5 | 2023-11-05T07:59:00+00:00
   6 | 2023-11-05T08:00:00+00:00
   7 | 2023-11-05T08:30:00+00:00
   8 | 2023-11-05T09:00:00+00:00
   9 | 2023-11-05T09:30:00+00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S%z"
table_utc = table.select(date_utc=pw.this.date_utc.dt.strptime(fmt=fmt))
table_local = table_utc.with_columns(
    date=pw.this.date_utc.dt.to_naive_in_timezone(timezone="America/Los_Angeles"),
)
pw.debug.compute_and_print(table_local, include_id=False)
date_utc                  | date
2023-03-12 09:59:00+00:00 | 2023-03-12 01:59:00
2023-03-12 10:00:00+00:00 | 2023-03-12 03:00:00
2023-03-13 09:59:00+00:00 | 2023-03-13 02:59:00
2023-03-13 10:00:00+00:00 | 2023-03-13 03:00:00
2023-11-05 07:59:00+00:00 | 2023-11-05 00:59:00
2023-11-05 08:00:00+00:00 | 2023-11-05 01:00:00
2023-11-05 08:30:00+00:00 | 2023-11-05 01:30:00
2023-11-05 09:00:00+00:00 | 2023-11-05 01:00:00
2023-11-05 09:30:00+00:00 | 2023-11-05 01:30:00

to_utc(from_timezone)

Converts DateTimeNaive to UTC from time zone provided as from_timezone argument. If the given DateTime doesn’t exist in the provided time zone it is mapped to the first existing DateTime after it. If a given DateTime corresponds to more than one moments in the provided time zone, it is mapped to a later moment.
  • Parameters
    from_timezone (Union[ColumnExpression, str]) – The time zone to convert from.
  • Returns
    DateTimeUtc

Examples:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         date
   1 | 2023-03-26T01:59:00
   2 | 2023-03-26T02:30:00
   3 | 2023-03-26T03:00:00
   4 | 2023-03-27T01:59:00
   5 | 2023-03-27T02:30:00
   6 | 2023-03-27T03:00:00
   7 | 2023-10-29T01:59:00
   8 | 2023-10-29T02:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_local = table.select(date=pw.this.date.dt.strptime(fmt=fmt))
table_utc = table_local.with_columns(
    date_utc=pw.this.date.dt.to_utc(from_timezone="Europe/Warsaw"),
)
pw.debug.compute_and_print(table_utc, include_id=False)
date                | date_utc
2023-03-26 01:59:00 | 2023-03-26 00:59:00+00:00
2023-03-26 02:30:00 | 2023-03-26 01:00:00+00:00
2023-03-26 03:00:00 | 2023-03-26 01:00:00+00:00
2023-03-27 01:59:00 | 2023-03-26 23:59:00+00:00
2023-03-27 02:30:00 | 2023-03-27 00:30:00+00:00
2023-03-27 03:00:00 | 2023-03-27 01:00:00+00:00
2023-10-29 01:59:00 | 2023-10-28 23:59:00+00:00
2023-10-29 02:00:00 | 2023-10-29 01:00:00+00:00

table = pw.debug.table_from_markdown(
    '''
     |         date
   1 | 2023-03-12T01:59:00
   2 | 2023-03-12T02:30:00
   3 | 2023-03-12T03:00:00
   4 | 2023-03-13T01:59:00
   5 | 2023-03-13T02:30:00
   6 | 2023-03-13T03:00:00
   7 | 2023-11-05T00:59:00
   8 | 2023-11-05T01:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_local = table.select(date=pw.this.date.dt.strptime(fmt=fmt))
table_utc = table_local.with_columns(
    date_utc=pw.this.date.dt.to_utc(from_timezone="America/Los_Angeles"),
)
pw.debug.compute_and_print(table_utc, include_id=False)
date                | date_utc
2023-03-12 01:59:00 | 2023-03-12 09:59:00+00:00
2023-03-12 02:30:00 | 2023-03-12 10:00:00+00:00
2023-03-12 03:00:00 | 2023-03-12 10:00:00+00:00
2023-03-13 01:59:00 | 2023-03-13 08:59:00+00:00
2023-03-13 02:30:00 | 2023-03-13 09:30:00+00:00
2023-03-13 03:00:00 | 2023-03-13 10:00:00+00:00
2023-11-05 00:59:00 | 2023-11-05 07:59:00+00:00
2023-11-05 01:00:00 | 2023-11-05 09:00:00+00:00

weeks()

The total number of weeks in a Duration.
  • Returns
    Weeks as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |         t1          |         t2
   0 | 2023-03-15T00:00:00 | 2023-05-15T10:13:23
   1 | 2023-04-15T00:00:00 | 2023-05-15T10:00:00
   2 | 2023-05-01T10:00:00 | 2023-05-15T10:00:00
   3 | 2023-05-15T10:00:00 | 2023-05-15T09:00:00
   4 | 2023-05-15T10:00:00 | 2023-05-15T11:00:00
   5 | 2023-05-16T12:13:00 | 2023-05-15T10:00:00
   6 | 2024-05-15T14:13:23 | 2023-05-15T10:00:00
'''
)
fmt = "%Y-%m-%dT%H:%M:%S"
table_with_datetimes = table.select(
    t1=pw.this.t1.dt.strptime(fmt=fmt), t2=pw.this.t2.dt.strptime(fmt=fmt)
)
table_with_diff = table_with_datetimes.select(diff=pw.this.t1 - pw.this.t2)
table_with_weeks = table_with_diff.select(weeks=pw.this["diff"].dt.weeks())
pw.debug.compute_and_print(table_with_weeks, include_id=False)
weeks
-8
-4
-2
0
0
0
52

year()

Extracts year from a DateTime.
  • Returns
    Year as int.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     |               t1
   1 | 1974-03-12T00:00:00
   2 | 2023-03-25T12:00:00
   3 | 2023-05-15T14:13:00
'''
)
table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
table_with_years = table_with_datetime.select(year=table_with_datetime.t1.dt.year())
pw.debug.compute_and_print(table_with_years, include_id=False)
year
1974
2023
2023

class pw.NumericalNamespace(expression)

A module containing methods related to numbers. They can be called using a num attribute of an expression.

Typical use:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | v
   1 | -1
'''
)
table_abs = table.select(v_abs=table.v.num.abs())

abs()

Returns the absolute value from a numerical value.
  • Returns
    Absolute value as float

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | v
   1 | 1
   2 | -1
   3 | 2.5
   4 | -2.5
'''
)
table_abs = table.select(v_abs=table.v.num.abs())
pw.debug.compute_and_print(table_abs, include_id=False)
v_abs
1.0
1.0
2.5
2.5

fill_na(default_value)

Fill the missing values (None or NaN) in a column of a table with a specified default value.
  • Parameters
    default_value (float) – The value to fill in for the missing values.
  • Returns
    A new column with the missing values filled with the specified default value.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | v
   1 | 1
   2 | 2.0
   3 | None
   4 | 3.5
'''
)
table_fill_na = table.select(v_filled=table.v.num.fill_na(0))
pw.debug.compute_and_print(table_fill_na, include_id=False)
v_filled
0.0
1.0
2.0
3.5

round(decimals=0)

Round the values in a column of a table to the specified number of decimals.
  • Parameters
    • decimals (Union[ColumnExpression, int]) – The number of decimal places to round to. It can be either an
    • 0. (integer* or *a reference to another column. Defaults to) –
  • Returns
    A new column with the values rounded to the specified number of decimals.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | v
   1 | -2.18
   2 | -1.11
   3 | 1
   4 | 2.1
   5 | 3.14
   6 | 4.17
'''
)
table_round = table.select(v_round=table.v.num.round(1))
pw.debug.compute_and_print(table_round, include_id=False)
v_round
-2.2
-1.1
1.0
2.1
3.1
4.2
import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | v      | precision
   1 | 3      | 0
   2 | 3.1    | 1
   3 | 3.14   | 1
   4 | 3.141  | 2
   5 | 3.1415 | 2
'''
)
table_round = table.select(v_round=table.v.num.round(pw.this.precision))
pw.debug.compute_and_print(table_round, include_id=False)
v_round
3.0
3.1
3.1
3.14
3.14

class pw.StringNamespace(expression)

A module containing methods related to string. They can be called using a str attribute of an expression.

Typical use:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | ALICE
'''
)
table += table.select(name_lower=table.name.str.lower())
pw.debug.compute_and_print(table, include_id=False)
name  | name_lower
ALICE | alice

count(sub, start=None, end=None)

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(
    '''
     | name
   1 | Alice
   2 | Hello
   3 | World
   4 | Zoo
'''
)
table += table.select(count=table.name.str.count("o"))
pw.debug.compute_and_print(table, include_id=False)
name  | count
Alice | 0
Hello | 1
World | 1
Zoo   | 2

endswith(suffix)

Returns True if the string ends with suffix.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(ends_with_e=table.name.str.endswith("e"))
pw.debug.compute_and_print(table, include_id=False)
name   | ends_with_e
Alice  | True
Bob    | False
CAROLE | False
david  | False

find(sub, start=None, end=None)

Return the lowest index in the string where substring sub is found within the slice s\[start:end\]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Hello
   3 | World
   4 | Zoo
'''
)
table += table.select(pos=table.name.str.find("o"))
pw.debug.compute_and_print(table, include_id=False)
name  | pos
Alice | -1
Hello | 4
World | 1
Zoo   | 1

len()

Returns the length of a string.
  • Returns
    Length of the string

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(length=table.name.str.len())
pw.debug.compute_and_print(table, include_id=False)
name   | length
Alice  | 5
Bob    | 3
CAROLE | 6
david  | 5

lower()

Returns a lowercase copy of a string.
  • Returns
    Lowercase string

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(name_lower=table.name.str.lower())
pw.debug.compute_and_print(table, include_id=False)
name   | name_lower
Alice  | alice
Bob    | bob
CAROLE | carole
david  | david

parse_bool(true_values=['on', 'true', 'yes', '1'], false_values=['off', 'false', 'no', '0'], optional=False)

Parses the string to bool, by checking if given string is either in true_values or false_values. The given string and all values in true_vales and false_values are made lowercase, so parsing is case insensitive.

When true_values and false_values arguments are not provided, strings “True”, “On”, “1” and “Yes” are interpreted as True value, and “False”, “Off”, “0”, and “No” are interpreted as False.

If true_values or false_values is provided, then these values are mapped to respectively True and False, while all other either raise an exception or return None, depending on argument optional.

If optional argument is set to True, then the return type is Optional[bool] and if some string cannot be parsed, None is returned.

Example:

import pathway as pw
import pandas as pd
df = pd.DataFrame({"a": ["0", "TRUE", "on"]}, dtype=str)
table = pw.debug.table_from_pandas(df)
table.schema.as_dict()
{'a': STR}
pw.debug.compute_and_print(table, include_id=False)
a
0
TRUE
on
table = table.select(a=table.a.str.parse_bool())
table.schema.as_dict()
{'a': BOOL}
pw.debug.compute_and_print(table, include_id=False)
a
False
True
True

parse_float(optional=False)

Parses the string to float. If optional argument is set to True, then the return type is Optional\[float\] and if some string cannot be parsed, None is returned.

Example:

import pathway as pw
import pandas as pd
df = pd.DataFrame({"a": ["-5", "0.1", "200.999"]}, dtype=str)
table = pw.debug.table_from_pandas(df)
table.schema.as_dict()
{'a': STR}
table = table.select(a=table.a.str.parse_float())
table.schema.as_dict()
{'a': FLOAT}
pw.debug.compute_and_print(table, include_id=False)
a
-5.0
0.1
200.999

parse_int(optional=False)

Parses the string to int. If optional argument is set to True, then the return type is Optional\[int\] and if some string cannot be parsed, None is returned.

Example:

import pathway as pw
import pandas as pd
df = pd.DataFrame({"a": ["-5", "0", "200"]}, dtype=str)
table = pw.debug.table_from_pandas(df)
table.schema.as_dict()
{'a': STR}
table = table.select(a=table.a.str.parse_int())
table.schema.as_dict()
{'a': INT}
pw.debug.compute_and_print(table, include_id=False)
a
-5
0
200

removeprefix(prefix, /)

If the string starts with prefix, returns a copy of the string without the prefix. Otherwise returns the original string.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(without_da=table.name.str.removeprefix("da"))
pw.debug.compute_and_print(table, include_id=False)
name   | without_da
Alice  | Alice
Bob    | Bob
CAROLE | CAROLE
david  | vid
table = pw.debug.table_from_markdown(
    '''
     | note | prefix
   1 | AAA  | A
   2 | BB   | B
'''
)
table = table.select(
   pw.this.note,
   new_note=pw.this.note.str.removeprefix(pw.this.prefix)
)
pw.debug.compute_and_print(table, include_id=False)
note | new_note
AAA  | AA
BB   | B

removesuffix(suffix, /)

If the string ends with suffix, returns a copy of the string without the suffix. Otherwise returns the original string.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(without_LE=table.name.str.removesuffix("LE"))
pw.debug.compute_and_print(table, include_id=False)
name   | without_LE
Alice  | Alice
Bob    | Bob
CAROLE | CARO
david  | david
table = pw.debug.table_from_markdown(
    '''
     | fruit  | suffix
   1 | bamboo | o
   2 | banana | na
'''
)
table = table.select(
   pw.this.fruit,
   fruit_cropped=pw.this.fruit.str.removesuffix(pw.this.suffix)
)
pw.debug.compute_and_print(table, include_id=False)
fruit  | fruit_cropped
bamboo | bambo
banana | bana

replace(old_value, new_value, count=-1, /)

Returns the a string where the occurrences of the old_value substrings are
replaced by the new_value substring.
  • Parameters
    count (Union[ColumnExpression, int]) – Maximum number of occurrences to replace. When set to -1, replaces all occurrences. Defaults to -1.
  • Returns
    The new string where old_value is replaced by new_value

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
   5 | Edward
'''
)
table += table.select(name_replace=table.name.str.replace("d","Z"))
pw.debug.compute_and_print(table, include_id=False)
name   | name_replace
Alice  | Alice
Bob    | Bob
CAROLE | CAROLE
Edward | EZwarZ
david  | ZaviZ
table = pw.debug.table_from_markdown(
    '''
     | value      | old | new | count
   1 | Scaciscics | c   | t   | 3
   2 | yelliwwiid | i   | o   | 2
'''
)
table = table.select(
   pw.this.value,
   value_replace=pw.this.value.str.replace(
      pw.this.old, pw.this.new, pw.this.count
   )
)
pw.debug.compute_and_print(table, include_id=False)
value      | value_replace
Scaciscics | Statistics
yelliwwiid | yellowwoid

reversed()

Returns a reverse copy of a string.
  • Returns
    Reverse string

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(name_reverse=table.name.str.reversed())
pw.debug.compute_and_print(table, include_id=False)
name   | name_reverse
Alice  | ecilA
Bob    | boB
CAROLE | ELORAC
david  | divad

rfind(sub, start=None, end=None)

Return the highest index in the string where substring sub is found within the slice s\[start:end\]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Hello
   3 | World
   4 | Zoo
'''
)
table += table.select(pos=table.name.str.rfind("o"))
pw.debug.compute_and_print(table, include_id=False)
name  | pos
Alice | -1
Hello | 4
World | 1
Zoo   | 2

slice(start, end, /)

Return a slice of the string.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(slice=table.name.str.slice(1,4))
pw.debug.compute_and_print(table, include_id=False)
name   | slice
Alice  | lic
Bob    | ob
CAROLE | ARO
david  | avi

startswith(prefix)

Returns True if the string starts with prefix.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(starts_with_A=table.name.str.startswith("A"))
pw.debug.compute_and_print(table, include_id=False)
name   | starts_with_A
Alice  | True
Bob    | False
CAROLE | False
david  | False

strip(chars=None)

Returns a copy of the string with specified leading and trailing characters removed. If no arguments are passed, remove the leading and trailing whitespaces.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(name_strip=table.name.str.strip("Aod"))
pw.debug.compute_and_print(table, include_id=False)
name   | name_strip
Alice  | lice
Bob    | Bob
CAROLE | CAROLE
david  | avi

swapcase()

Returns a copy of the string where the case is inverted.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(name_swap=table.name.str.swapcase())
pw.debug.compute_and_print(table, include_id=False)
name   | name_swap
Alice  | aLICE
Bob    | bOB
CAROLE | carole
david  | DAVID

title()

Returns a copy of the string where where words start with an uppercase character and the remaining characters are lowercase.

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | col
   1 | title
'''
)
table = table.select(col_title=table.col.str.title())
pw.debug.compute_and_print(table, include_id=False)
col_title
Title

upper()

Returns a uppercase copy of a string.
  • Returns
    Uppercase string

Example:

import pathway as pw
table = pw.debug.table_from_markdown(
    '''
     | name
   1 | Alice
   2 | Bob
   3 | CAROLE
   4 | david
'''
)
table += table.select(name_upper=table.name.str.upper())
pw.debug.compute_and_print(table, include_id=False)
name   | name_upper
Alice  | ALICE
Bob    | BOB
CAROLE | CAROLE
david  | DAVID