The polars.DataFrame.min_horizontal
function is designed to find the minimum value horizontally across columns in a DataFrame
. It returns a series containing the minimum values across each row, named min.
DataFrame.min_horizontal()
This function takes no additional parameters. This function returns a series named min containing the minimum values across each row.
Now let’s see the code below to see the working of min_horizontal
function in Polars:
import polars as pldf = pl.DataFrame({'length': [10, 12, 23, 65],'width': [40, 5, 62, 32],'height': [70, 8, 9, 23]})min_val = df.min_horizontal()print(min_val)
Lines 3–7: We created a DataFrame
named df
is created. The DataFrame
has three columns (length
, width
, height
) and four rows, with corresponding values provided in lists.
Line 9: We applied min_horizontal
function to the DataFrame
df
to find the minimum values horizontally across each row. The result is assigned to the variable min_val
, which will be a series containing the minimum values, with the name min. The min_horizontal
function will find the minimum values across each row:
For row 0: The minimum value is 10
.
For row 1: The minimum value is 5
.
For row 2: The minimum value is 9
.
For row 3: The minimum value is 23
.
Line 10: Finally, the minimum values across each row, stored in the Series min_val
, are printed to the console.
The polars.DataFrame.min_horizontal
function in Polars provides a convenient way to find the minimum values horizontally across each row of a DataFrame
. By applying this function, one obtains a series containing the minimum values with the name min. This facilitates quick and efficient analysis of row-wise minimum values in tabular data, offering valuable insights into the smallest values within each record of the DataFrame
.
Free Resources