[e988c2]: / docs / includes / generated_docs / language__series.md

Download this file

3410 lines (2866 with data), 116.5 kB


class BoolPatientSeries()

One row per patient series of type boolean

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self & other 🔗

Logical AND

Return a boolean series which is True where both this series and other are
True, False where either are False, and NULL otherwise.

Example usage:

is_female_and_alive = patients.is_alive_on("2020-01-01") & patients.sex.is_in(["female"])
self | other 🔗

Logical OR

Return a boolean series which is True where either this series or other is
True, False where both are False, and NULL otherwise.

Example usage:

is_alive = patients.date_of_death.is_null() | patients.date_of_death.is_after("2020-01-01")

Note that the above example is equivalent to patients.is_alive_on("2020-01-01").

~ self 🔗

Logical NOT

Return a boolean series which is the inverse of this series i.e. where True
becomes False, False becomes True, and NULL stays as NULL.

Example usage:

is_born_outside_period = ~ patients.date_of_birth.is_on_or_between("2020-03-01", "2020-06-30")
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this Boolean series as 1 (True) or 0 (False).


class BoolEventSeries()

Multiple rows per patient series of type boolean

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self & other 🔗

Logical AND

Return a boolean series which is True where both this series and other are
True, False where either are False, and NULL otherwise.

Example usage:

is_female_and_alive = patients.is_alive_on("2020-01-01") & patients.sex.is_in(["female"])
self | other 🔗

Logical OR

Return a boolean series which is True where either this series or other is
True, False where both are False, and NULL otherwise.

Example usage:

is_alive = patients.date_of_death.is_null() | patients.date_of_death.is_after("2020-01-01")

Note that the above example is equivalent to patients.is_alive_on("2020-01-01").

~ self 🔗

Logical NOT

Return a boolean series which is the inverse of this series i.e. where True
becomes False, False becomes True, and NULL stays as NULL.

Example usage:

is_born_outside_period = ~ patients.date_of_birth.is_on_or_between("2020-03-01", "2020-06-30")
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this Boolean series as 1 (True) or 0 (False).

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()


class StrPatientSeries()

One row per patient series of type string

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
contains(other) 🔗

Return a boolean series which is True for each string in this series which
contains other as a sub-string and False otherwise. For NULL values, the
result is NULL.

Example usage:

is_female = patients.sex.contains("fem")

other can be another string series, in which case corresponding values
are compared. If either value is NULL the result is NULL.


class StrEventSeries()

Multiple rows per patient series of type string

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
contains(other) 🔗

Return a boolean series which is True for each string in this series which
contains other as a sub-string and False otherwise. For NULL values, the
result is NULL.

Example usage:

is_female = patients.sex.contains("fem")

other can be another string series, in which case corresponding values
are compared. If either value is NULL the result is NULL.

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()
minimum_for_patient() 🔗

Return the minimum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.minimum_for_patient()
maximum_for_patient() 🔗

Return the maximum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.maximum_for_patient()


class IntPatientSeries()

One row per patient series of type integer

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self + other 🔗

Return the sum of each corresponding value in this series and other (or NULL
if either is NULL).

self - other 🔗

Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).

self * other 🔗

Return the product of each corresponding value in this series and other (or
NULL if either is NULL).

self / other 🔗

Return a series with each value in this series divided by its correponding value
in other (or NULL if either is NULL).

Note that the result is always if a float even if the inputs are integers.

self // other 🔗

Return a series with each value in this series divided by its correponding value
in other and then rounded down to the nearest integer value (or NULL if either
is NULL).

Note that the result is always if an integer even if the inputs are floats.

- self 🔗

Return the negation of each value in this series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this series rounded down to the nearest integer.

as_float() 🔗

Return each value in this series as a float (e.g. 10 becomes 10.0).


class IntEventSeries()

Multiple rows per patient series of type integer

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self + other 🔗

Return the sum of each corresponding value in this series and other (or NULL
if either is NULL).

self - other 🔗

Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).

self * other 🔗

Return the product of each corresponding value in this series and other (or
NULL if either is NULL).

self / other 🔗

Return a series with each value in this series divided by its correponding value
in other (or NULL if either is NULL).

Note that the result is always if a float even if the inputs are integers.

self // other 🔗

Return a series with each value in this series divided by its correponding value
in other and then rounded down to the nearest integer value (or NULL if either
is NULL).

Note that the result is always if an integer even if the inputs are floats.

- self 🔗

Return the negation of each value in this series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this series rounded down to the nearest integer.

as_float() 🔗

Return each value in this series as a float (e.g. 10 becomes 10.0).

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()
minimum_for_patient() 🔗

Return the minimum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.minimum_for_patient()
maximum_for_patient() 🔗

Return the maximum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.maximum_for_patient()
sum_for_patient() 🔗

Return the sum of all values in the series for each patient.

mean_for_patient() 🔗

Return the arithmetic mean of any non-NULL values in the series for each
patient.


class FloatPatientSeries()

One row per patient series of type float

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self + other 🔗

Return the sum of each corresponding value in this series and other (or NULL
if either is NULL).

self - other 🔗

Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).

self * other 🔗

Return the product of each corresponding value in this series and other (or
NULL if either is NULL).

self / other 🔗

Return a series with each value in this series divided by its correponding value
in other (or NULL if either is NULL).

Note that the result is always if a float even if the inputs are integers.

self // other 🔗

Return a series with each value in this series divided by its correponding value
in other and then rounded down to the nearest integer value (or NULL if either
is NULL).

Note that the result is always if an integer even if the inputs are floats.

- self 🔗

Return the negation of each value in this series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this series rounded down to the nearest integer.

as_float() 🔗

Return each value in this series as a float (e.g. 10 becomes 10.0).


class FloatEventSeries()

Multiple rows per patient series of type float

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self + other 🔗

Return the sum of each corresponding value in this series and other (or NULL
if either is NULL).

self - other 🔗

Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).

self * other 🔗

Return the product of each corresponding value in this series and other (or
NULL if either is NULL).

self / other 🔗

Return a series with each value in this series divided by its correponding value
in other (or NULL if either is NULL).

Note that the result is always if a float even if the inputs are integers.

self // other 🔗

Return a series with each value in this series divided by its correponding value
in other and then rounded down to the nearest integer value (or NULL if either
is NULL).

Note that the result is always if an integer even if the inputs are floats.

- self 🔗

Return the negation of each value in this series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
as_int() 🔗

Return each value in this series rounded down to the nearest integer.

as_float() 🔗

Return each value in this series as a float (e.g. 10 becomes 10.0).

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()
minimum_for_patient() 🔗

Return the minimum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.minimum_for_patient()
maximum_for_patient() 🔗

Return the maximum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.maximum_for_patient()
sum_for_patient() 🔗

Return the sum of all values in the series for each patient.

mean_for_patient() 🔗

Return the arithmetic mean of any non-NULL values in the series for each
patient.


class DatePatientSeries()

One row per patient series of type date

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self - other 🔗

Return a series giving the difference between each date in this series and
other (see DateDifference).

Example usage:

age_months = (date("2020-01-01") - patients.date_of_birth).months
year 🔗

Return an integer series giving the year of each date in this series.

month 🔗

Return an integer series giving the month (1-12) of each date in this series.

Return an integer series giving the day of the month (1-31) of each date in this
series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
to_first_of_year() 🔗

Return a date series with each date in this series replaced by the date of the
first day in its corresponding calendar year.

Example usage:

patients.date_of_death.to_first_of_year()
to_first_of_month() 🔗

Return a date series with each date in this series replaced by the date of the
first day in its corresponding calendar month.

Example usage:

patients.date_of_death.to_first_of_month()
is_before(other) 🔗

Return a boolean series which is True for each date in this series that is
strictly earlier than its corresponding date in other and False otherwise
(or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_before("2020-04-01"))
is_on_or_before(other) 🔗

Return a boolean series which is True for each date in this series that is
earlier than or the same as its corresponding value in other and False
otherwise (or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_on_or_before("2020-03-31"))
is_after(other) 🔗

Return a boolean series which is True for each date in this series that is
strictly later than its corresponding date in other and False otherwise
(or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_after("2020-03-31"))
is_on_or_after(other) 🔗

Return a boolean series which is True for each date in this series that is later
than or the same as its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_on_or_after("2020-04-01"))
is_between_but_not_on(start, end) 🔗

Return a boolean series which is True for each date in this series which is
strictly between (i.e. not equal to) the corresponding dates in start and end,
and False otherwise.

Example usage:

medications.where(medications.date.is_between_but_not_on("2020-03-31", "2021-04-01"))

For each trio of dates being compared, if any date is NULL the result is NULL.

is_on_or_between(start, end) 🔗

Return a boolean series which is True for each date in this series which is
between or the same as the corresponding dates in start and end, and
False otherwise.

Example usage:

medications.where(medications.date.is_on_or_between("2020-04-01", "2021-03-31"))

For each trio of dates being compared, if any date is NULL the result is NULL.

is_during(interval) 🔗

The same as is_on_or_between() above, but allows supplying a start/end date
pair as single argument.

Example usage:

study_period = ("2020-04-01", "2021-03-31")
medications.where(medications.date.is_during(study_period))

Also see the docs on using is_during with the
INTERVAL placeholder.


class DateEventSeries()

Multiple rows per patient series of type date

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
self > other 🔗

Return a boolean series which is True for each value in this series that is
strictly less than its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") < 18
self >= other 🔗

Return a boolean series which is True for each value in this series that is less
than or equal to its corresponding value in other and False otherwise (or NULL
if either value is NULL).

Example usage:

is_underage = patients.age_on("2020-01-01") <= 17
self <= other 🔗

Return a boolean series which is True for each value in this series that is
greater than or equal to its corresponding value in other and False otherwise
(or NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") >= 18
self < other 🔗

Return a boolean series which is True for each value in this series that is
strictly greater than its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

is_adult = patients.age_on("2020-01-01") > 17
self - other 🔗

Return a series giving the difference between each date in this series and
other (see DateDifference).

Example usage:

age_months = (date("2020-01-01") - patients.date_of_birth).months
year 🔗

Return an integer series giving the year of each date in this series.

month 🔗

Return an integer series giving the month (1-12) of each date in this series.

Return an integer series giving the day of the month (1-31) of each date in this
series.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
to_first_of_year() 🔗

Return a date series with each date in this series replaced by the date of the
first day in its corresponding calendar year.

Example usage:

patients.date_of_death.to_first_of_year()
to_first_of_month() 🔗

Return a date series with each date in this series replaced by the date of the
first day in its corresponding calendar month.

Example usage:

patients.date_of_death.to_first_of_month()
is_before(other) 🔗

Return a boolean series which is True for each date in this series that is
strictly earlier than its corresponding date in other and False otherwise
(or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_before("2020-04-01"))
is_on_or_before(other) 🔗

Return a boolean series which is True for each date in this series that is
earlier than or the same as its corresponding value in other and False
otherwise (or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_on_or_before("2020-03-31"))
is_after(other) 🔗

Return a boolean series which is True for each date in this series that is
strictly later than its corresponding date in other and False otherwise
(or NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_after("2020-03-31"))
is_on_or_after(other) 🔗

Return a boolean series which is True for each date in this series that is later
than or the same as its corresponding value in other and False otherwise (or
NULL if either value is NULL).

Example usage:

medications.where(medications.date.is_on_or_after("2020-04-01"))
is_between_but_not_on(start, end) 🔗

Return a boolean series which is True for each date in this series which is
strictly between (i.e. not equal to) the corresponding dates in start and end,
and False otherwise.

Example usage:

medications.where(medications.date.is_between_but_not_on("2020-03-31", "2021-04-01"))

For each trio of dates being compared, if any date is NULL the result is NULL.

is_on_or_between(start, end) 🔗

Return a boolean series which is True for each date in this series which is
between or the same as the corresponding dates in start and end, and
False otherwise.

Example usage:

medications.where(medications.date.is_on_or_between("2020-04-01", "2021-03-31"))

For each trio of dates being compared, if any date is NULL the result is NULL.

is_during(interval) 🔗

The same as is_on_or_between() above, but allows supplying a start/end date
pair as single argument.

Example usage:

study_period = ("2020-04-01", "2021-03-31")
medications.where(medications.date.is_during(study_period))

Also see the docs on using is_during with the
INTERVAL placeholder.

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()
minimum_for_patient() 🔗

Return the minimum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.minimum_for_patient()
maximum_for_patient() 🔗

Return the maximum value in the series for each patient (or NULL if the patient
has no values).

Example usage:

clinical_events.where(...).numeric_value.maximum_for_patient()
count_episodes_for_patient(maximum_gap) 🔗

Counts the number of "episodes" for each patient where dates which are no more
than maximum_gap apart are considered part of the same episode. The
maximum_gap duration can be specified in days() or
weeks().

For example, suppose a patient has the following sequence of events:

Event ID Date
A 2020-01-01
B 2020-01-04
C 2020-01-06
D 2020-01-10
E 2020-01-12

And suppose we count the episodes here using a maximum gap of three days:

.count_episodes_for_patient(days(3))

We will get an episode count of two: events A, B and C are considered as one
episode and events D and E as another.

Note that events A and C are considered part of the same episode even though
they are more than three days apart because event B is no more than three days
apart from both of them. That is, the clock restarts with each new event in an
episode rather than running from the first event in an episode.


class CodePatientSeries()

One row per patient series of type code

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
to_category(categorisation, default=None) 🔗

An alias for map_values which makes the intention clearer when working with
codelists.

For more detail see codelist_from_csv() and the
how-to guide.


class CodeEventSeries()

Multiple rows per patient series of type code

self == other 🔗

Return a boolean series comparing each value in this series with its
corresponding value in other.

Note that the result of comparing anything with NULL (including NULL itself) is NULL.

Example usage:

patients.sex == "female"
self != other 🔗

Return the inverse of == above.

Note that the same point regarding NULL applies here.

Example usage:

patients.sex != "unknown"
is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

Return a boolean series which is True for each value in this series which is
contained in other.

See how to combine is_in with a codelist in
the how-to guide.

Example usage:

medications.dmd_code.is_in(["39113311000001107", "39113611000001102"])

other accepts any of the standard "container" types (tuple, list, set, frozenset,
or dict) or another event series.

is_not_in(other) 🔗

Return the inverse of is_in() above.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
to_category(categorisation, default=None) 🔗

An alias for map_values which makes the intention clearer when working with
codelists.

For more detail see codelist_from_csv() and the
how-to guide.

count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()


class MultiCodeStringPatientSeries()

One row per patient series of type multi code string

self == other 🔗

This operation is not allowed because it is unlikely you would want to match the
values in this field with an exact string e.g.

apcs.all_diagnoses == "||I302, K201, J180 || I302, K200, M920"

Instead you should use the contains or contains_any_of methods.

self != other 🔗

See above.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

This operation is not allowed. To check for the presence of any codes in
a codelist, please use the contains_any_of(codelist) method instead.

is_not_in(other) 🔗

This operation is not allowed. To check for the absence of all codes in a codelist,
from a column called column, please use ~column.contains_any_of(codelist).
NB the contains_any_of(codelist) will provide any records that contain any of the
codes, which is then negated with the ~ operator.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
contains(code) 🔗

Check if the multi code field contains a specific code string and
return the result as a boolean series. code can
either be a string (and prefix matching works so e.g. "N17" in ICD-10
would match all acute renal failure), or a clinical code.

Example usages:

all_diagnoses.contains("N17")
all_diagnoses.contains(ICD10Code("N170"))
contains_any_of(codelist) 🔗

Check if any of the codes in codelist occur in the multi code field and
return the result as a boolean series.
As with the contains(code) method, the codelist can be a mixture of clinical
codes and string prefixes, as seen in the example below.

Example usage:

all_diagnoses.contains([ICD10Code("N170"), "N17"])


class MultiCodeStringEventSeries()

Multiple rows per patient series of type multi code string

self == other 🔗

This operation is not allowed because it is unlikely you would want to match the
values in this field with an exact string e.g.

apcs.all_diagnoses == "||I302, K201, J180 || I302, K200, M920"

Instead you should use the contains or contains_any_of methods.

self != other 🔗

See above.

is_null() 🔗

Return a boolean series which is True for each NULL value in this
series and False for each non-NULL value.

Example usage:

patients.date_of_death.is_null()
is_not_null() 🔗

Return the inverse of is_null() above.

Example usage:

patients.date_of_death.is_not_null()
when_null_then(other) 🔗

Replace any NULL value in this series with the corresponding value in other.

Note that other must be of the same type as this series.

Example usage:

(patients.date_of_death < "2020-01-01").when_null_then(False)
is_in(other) 🔗

This operation is not allowed. To check for the presence of any codes in
a codelist, please use the contains_any_of(codelist) method instead.

is_not_in(other) 🔗

This operation is not allowed. To check for the absence of all codes in a codelist,
from a column called column, please use ~column.contains_any_of(codelist).
NB the contains_any_of(codelist) will provide any records that contain any of the
codes, which is then negated with the ~ operator.

map_values(mapping, default=None) 🔗

Return a new series with mapping applied to each value. mapping should
be a dictionary mapping one set of values to another.

Example usage:

school_year = patients.age_on("2020-09-01").map_values(
    {13: "Year 9", 14: "Year 10", 15: "Year 11"},
    default="N/A"
)
contains(code) 🔗

Check if the multi code field contains a specific code string and
return the result as a boolean series. code can
either be a string (and prefix matching works so e.g. "N17" in ICD-10
would match all acute renal failure), or a clinical code.

Example usages:

all_diagnoses.contains("N17")
all_diagnoses.contains(ICD10Code("N170"))
contains_any_of(codelist) 🔗

Check if any of the codes in codelist occur in the multi code field and
return the result as a boolean series.
As with the contains(code) method, the codelist can be a mixture of clinical
codes and string prefixes, as seen in the example below.

Example usage:

all_diagnoses.contains([ICD10Code("N170"), "N17"])
count_distinct_for_patient() 🔗

Return an integer patient series counting the number of
distinct values for each patient in the series (ignoring any NULL values).

Note that if a patient has no values at all in the series the result will
be zero rather than NULL.

Example usage:

medications.dmd_code.count_distinct_for_patient()