• Post author:
  • Post category:Polars
  • Post last modified:May 16, 2025
  • Reading time:9 mins read
You are currently viewing Polars Series describe() – Usage & Examples

In Polars, the Series.describe() method generates a quick statistical summary of a Series. It’s a convenient way to understand the distribution, central tendency, and variability of numeric data, similar to Pandas’ describe() but tailored for Polars’ fast and efficient data processing.

Advertisements

In this article, I will explain the Polars Series describe() function, covering its syntax, parameters, and usage, and explain how it returns a Polars DataFrame containing summary statistics like count, mean, std, min, max, and the specified percentiles.

Key Points –

  • Provides summary statistics of a Polars Series, including count, mean, standard deviation, min, max, and percentiles.
  • Automatically excludes null (NaN) values when calculating statistics.
  • Supports custom percentile values via the percentiles parameter.
  • Default percentiles provided are the 25th, 50th (median), and 75th percentiles.
  • Allows customization of the interpolation method used for percentile calculations.
  • Returns results as a Polars DataFrame with two columns: statistic name and value.
  • Works with numeric data types; non-numeric data may not be supported for descriptive statistics.
  • Supports interpolation methods for percentile calculation (default: ‘nearest’).

Polars Series describe() Introduction

Let’s know the syntax of the series describe() method.


# Syntax of describe()
Series.describe(
percentiles: Sequence[float] | float | None = (0.25, 0.5, 0.75),
interpolation: RollingInterpolationMethod = 'nearest',
) → DataFrame

Parameters of the Series describe()

Following are the parameters of the series describe() method.

  • percentiles (optional) – A float or list of floats specifying which quantiles to include (default is 25%, 50%, and 75%).
  • interpolation (optional) – Method used to interpolate between data points when calculating percentiles (default is 'nearest').

Return Value

This function returns a polars DataFrame containing summary statistics of the Series.

Usage of Polars Series.describe() Method

The Series.describe() method computes and returns a summary of key statistics for the polars Series. It provides a quick overview of the data, including metrics like count, number of null values, mean, standard deviation, minimum and maximum values, and important percentiles (25%, 50%, and 75%). This helps you quickly understand the distribution, central tendency, and spread of the numeric data within the Series.

Now, let’s create a Polars Series.


import polars as pl

ser = pl.Series("numbers", [10, 20, 30, 40, 50])
print("Original Series:\n", ser)

Yields below output.

polars series describe

You can use the describe() function on a Series or DataFrame to get basic descriptive statistics like count, mean, std, min, max, and percentiles by default.


# Using describe() to get basic statistics
ser2 = ser.describe()
print("Summary Statistics:\n", ser2)

Here,

  • Computes and returns key statistics like count, null count, mean, standard deviation, min, max, and quartiles (25%, 50%, 75%).
polars series describe

Custom Percentiles 10th and 90th Percentile

To get custom percentiles like the 10th and 90th percentiles using Polars’ describe() function, you can pass a list of percentiles as a parameter.


# Using describe() with custom percentiles: 10th and 90th percentile
ser2 = ser.describe(percentiles=[0.1, 0.9])
print("Descriptive statistics with custom percentiles:\n", ser2)

# Output:
# Descriptive statistics with custom percentiles:
3 shape: (8, 2)
┌────────────┬───────────┐
│ statistic  ┆ value     │
│ ---        ┆ ---       │
│ str        ┆ f64       │
╞════════════╪═══════════╡
│ count      ┆ 5.0       │
│ null_count ┆ 0.0       │
│ mean       ┆ 30.0      │
│ std        ┆ 15.811388 │
│ min        ┆ 10.0      │
│ 10%        ┆ 10.0      │
│ 90%        ┆ 50.0      │
│ max        ┆ 50.0      │
└────────────┴───────────┘

Change Interpolation Method to ‘linear’

When using describe() with percentiles, you can specify the interpolation method to determine how the percentiles are computed.

To set the interpolation method to 'linear', simply include the interpolation argument when calling describe().


# Describe with custom percentiles and linear interpolation
ser2 = ser.describe(percentiles=[0.1, 0.9], interpolation='linear')
print("Descriptive statistics with custom percentiles and linear interpolation:\n", ser2)

# Output:
# Descriptive statistics with custom percentiles and linear interpolation:
# shape: (8, 2)
┌────────────┬───────────┐
│ statistic  ┆ value     │
│ ---        ┆ ---       │
│ str        ┆ f64       │
╞════════════╪═══════════╡
│ count      ┆ 5.0       │
│ null_count ┆ 0.0       │
│ mean       ┆ 30.0      │
│ std        ┆ 15.811388 │
│ min        ┆ 10.0      │
│ 10%        ┆ 14.0      │
│ 90%        ┆ 46.0      │
│ max        ┆ 50.0      │
└────────────┴───────────┘

Excluding NaN Values in Summary Statistics

By default, Polars’ describe() function excludes NaN values when computing summary statistics, so you usually don’t have to do anything special.


import polars as pl

# Create a Series with some NaN values
ser_with_nan = pl.Series("numbers", [10, 20, None, 40, 50])

# Describe ignoring NaN (default behavior)
ser2 = ser_with_nan.describe()
print("\nDescriptive statistics excluding NaN values:\n", ser2)

# Output:
# Descriptive statistics excluding NaN values:
# shape: (9, 2)
┌────────────┬───────────┐
│ statistic  ┆ value     │
│ ---        ┆ ---       │
│ str        ┆ f64       │
╞════════════╪═══════════╡
│ count      ┆ 4.0       │
│ null_count ┆ 1.0       │
│ mean       ┆ 30.0      │
│ std        ┆ 18.257419 │
│ min        ┆ 10.0      │
│ 25%        ┆ 20.0      │
│ 50%        ┆ 40.0      │
│ 75%        ┆ 40.0      │
│ max        ┆ 50.0      │
└────────────┴───────────┘

Series with Negative and Positive Numbers

Creating a Polars Series that includes both negative and positive numbers, and then obtaining its descriptive statistics by applying the Series.describe() method.


import polars as pl

# Series with negative and positive numbers
ser = pl.Series("numbers", [-50, -20, 0, 30, 60])

# Get descriptive statistics
ser2 = ser.describe()
print("Descriptive statistics:\n", ser2)

# Output:
# Descriptive statistics:
# shape: (9, 2)
┌────────────┬───────────┐
│ statistic  ┆ value     │
│ ---        ┆ ---       │
│ str        ┆ f64       │
╞════════════╪═══════════╡
│ count      ┆ 5.0       │
│ null_count ┆ 0.0       │
│ mean       ┆ 4.0       │
│ std        ┆ 42.778499 │
│ min        ┆ -50.0     │
│ 25%        ┆ -20.0     │
│ 50%        ┆ 0.0       │
│ 75%        ┆ 30.0      │
│ max        ┆ 60.0      │
└────────────┴───────────┘

Conclusion

In conclusion, the polars Series.describe() is a powerful and convenient method for quickly generating a comprehensive statistical summary of your data. It provides essential descriptive statistics such as count, mean, standard deviation, min, max, and customizable percentiles, all while gracefully handling missing values.

Happy Learning!!

Reference