Range

We wish to obtain the range (minimum and maximum) values of a column or a vector.

Note that while it is most common to compute the range for numeric data, we may compute the range (min and max values) for other data types to mean the following:

  • For numeric: The smallest and largest numeric values.
  • For string: The alphabetically first and last string values.
  • For date-time: The earliest and latest date-time values.
  • For ordinal (sorted categorical): The values with the smallest and largest order.

In this example, we wish to obtain the minimum and maximum values of the column col_1 of the data frame df.

df['col_1'].min()
df['col_1'].max()

Here is how this works:

We use the methods min() and max() of a Pandas Series to obtain the minimum and maximum value of a Series respectively.

Alternative: via Built-In Functions

In this example, we wish to obtain the minimum and maximum values of a list called my_list.

min(my_list)
max(my_list)

Here is how this works:

  • We use the built-in Python functions min() and max() to obtain the minimum and maximum values of the list my_list.
  • The built-in functions min() and max() may be applied to both Series and non-Series vector objects such as lists.
PYTHON
I/O