Use the between() function to evaluate whether the column value is between the lower and upper bounds. The lower and upper bounds are inclusive
Required Parameters
- lower
- Specifies the lower bound value.
- upper
- Specifies the upper bound value.
Example setup
>>> from teradataml import *
>>> load_example_data("dataframe","sales")
>>> df = DataFrame.from_table('sales')
>>> df
Feb Jan Mar Apr datetime accounts Blue Inc 90.0 50.0 95.0 101.0 04/01/2017 Alpha Co 210.0 200.0 215.0 250.0 04/01/2017 Jones LLC 200.0 150.0 140.0 180.0 04/01/2017 Yellow Inc 90.0 NaN NaN NaN 04/01/2017 Orange Inc 210.0 NaN NaN 250.0 04/01/2017 Red Inc 200.0 150.0 140.0 NaN 04/01/2017
Example 1: Check if column 'Feb' is between 100 and 200
>>> new_df = df[df.Feb.between(100, 200)]
>>> print(new_df)
Feb Jan Mar Apr datetime accounts Jones LLC 200.0 150 140 180.0 04/01/2017 Red Inc 200.0 150 140 NaN 04/01/2017
Example 2: Check if column 'datetime' is between '01-01-2017' and '30-01-2017'
>>> new_df = df[df.datetime.between('01-01-2017', '30-01-2017')]
>>> print(new_df)
Feb Jan Mar Apr datetime accounts Jones LLC 200.0 150.0 140.0 180.0 04/01/2017 Blue Inc 90.0 50.0 95.0 101.0 04/01/2017 Yellow Inc 90.0 NaN NaN NaN 04/01/2017 Red Inc 200.0 150.0 140.0 NaN 04/01/2017 Alpha Co 210.0 200.0 215.0 250.0 04/01/2017 Orange Inc 210.0 NaN NaN 250.0 04/01/2017