One row per patient series of type boolean
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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"])
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")
.
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")
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this Boolean series as 1 (True) or 0 (False).
Multiple rows per patient series of type boolean
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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"])
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")
.
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")
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this Boolean series as 1 (True) or 0 (False).
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()
One row per patient series of type string
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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.
Multiple rows per patient series of type string
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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.
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()
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()
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()
One row per patient series of type integer
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
Return the sum of each corresponding value in this series and other
(or NULL
if either is NULL).
Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).
Return the product of each corresponding value in this series and other
(or
NULL if either is NULL).
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.
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.
Return the negation of each value in this series.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this series rounded down to the nearest integer.
Return each value in this series as a float (e.g. 10 becomes 10.0).
Multiple rows per patient series of type integer
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
Return the sum of each corresponding value in this series and other
(or NULL
if either is NULL).
Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).
Return the product of each corresponding value in this series and other
(or
NULL if either is NULL).
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.
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.
Return the negation of each value in this series.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this series rounded down to the nearest integer.
Return each value in this series as a float (e.g. 10 becomes 10.0).
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()
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()
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()
Return the sum of all values in the series for each patient.
Return the arithmetic mean of any non-NULL values in the series for each
patient.
One row per patient series of type float
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
Return the sum of each corresponding value in this series and other
(or NULL
if either is NULL).
Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).
Return the product of each corresponding value in this series and other
(or
NULL if either is NULL).
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.
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.
Return the negation of each value in this series.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this series rounded down to the nearest integer.
Return each value in this series as a float (e.g. 10 becomes 10.0).
Multiple rows per patient series of type float
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
Return the sum of each corresponding value in this series and other
(or NULL
if either is NULL).
Return each value in this series with its corresponding value in other
subtracted (or NULL if either is NULL).
Return the product of each corresponding value in this series and other
(or
NULL if either is NULL).
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.
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.
Return the negation of each value in this series.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
Return each value in this series rounded down to the nearest integer.
Return each value in this series as a float (e.g. 10 becomes 10.0).
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()
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()
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()
Return the sum of all values in the series for each patient.
Return the arithmetic mean of any non-NULL values in the series for each
patient.
One row per patient series of type date
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
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
Return an integer series giving the year of each date in this series.
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.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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()
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()
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"))
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"))
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"))
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"))
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.
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.
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.
Multiple rows per patient series of type date
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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
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
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
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
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
Return an integer series giving the year of each date in this series.
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.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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()
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()
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"))
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"))
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"))
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"))
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.
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.
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.
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()
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()
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()
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.
One row per patient series of type code
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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.
Multiple rows per patient series of type code
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"
Return the inverse of ==
above.
Note that the same point regarding NULL applies here.
Example usage:
patients.sex != "unknown"
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
Return the inverse of is_in()
above.
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"
)
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.
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()
One row per patient series of type multi code string
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.
See above.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
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.
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"
)
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"))
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"])
Multiple rows per patient series of type multi code string
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.
See above.
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()
Return the inverse of is_null()
above.
Example usage:
patients.date_of_death.is_not_null()
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)
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.
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.
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"
)
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"))
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"])
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()