Last modified: May 08, 2026 By Alexander Williams

Explore Data with Polars Shape, Head

Getting started with a new dataset can feel overwhelming. You need to understand its structure, size, and quality before any analysis.

Polars provides simple, fast methods to inspect your data. This guide covers the four essential functions: shape, dtypes, head, and describe.

These tools help you spot missing values, check data types, and see the first few rows. Let's dive in with clear examples.

Setup: Creating a Sample DataFrame

First, we need a DataFrame to explore. We'll use a small dataset of sales transactions.

Make sure you have Polars installed. If not, read our Install Polars in Python Step by Step guide first.


import polars as pl

# Create a simple sales DataFrame
data = {
    "order_id": [101, 102, 103, 104, 105],
    "product": ["Laptop", "Mouse", "Keyboard", "Monitor", "Laptop"],
    "price": [1200.50, 25.99, 45.00, 350.00, None],  # None is missing data
    "quantity": [2, 5, 3, 1, 2],
    "date": ["2024-01-15", "2024-01-16", "2024-01-16", "2024-01-17", "2024-01-18"]
}

df = pl.DataFrame(data)
print("DataFrame created successfully!")

DataFrame created successfully!

Using shape to Check Dimensions

The shape method returns a tuple with the number of rows and columns.

This is the fastest way to understand your dataset's size. A large shape means more data to process.


# Get the shape of the DataFrame
rows, cols = df.shape
print(f"Rows: {rows}, Columns: {cols}")

Rows: 5, Columns: 5

Our dataset has 5 rows and 5 columns. Simple but vital for memory planning.

Tip: Use shape early to confirm your data loaded correctly.

Inspecting Data Types with dtypes

The dtypes method shows the data type of every column.

Knowing types helps avoid errors. For example, mixing strings and numbers causes calculation problems.


# Check data types of all columns
print(df.dtypes)

[Int64, Utf8, Float64, Int64, Utf8]

Here, price is Float64 (decimal), quantity is Int64 (integer), and date is Utf8 (string).

Notice date is a string. For time series, convert it to a date type. See our Polars DataFrames and Series Guide for type conversion.

Previewing Data with head

The head method shows the first few rows. By default, it shows 5 rows.

This is perfect for a quick visual check. You can see column names and sample values.


# Show first 5 rows (default)
print(df.head())

shape: (5, 5)
┌──────────┬─────────┬────────┬──────────┬────────────┐
│ order_id ┆ product ┆ price  ┆ quantity ┆ date       │
│ ---      ┆ ---     ┆ ---    ┆ ---      ┆ ---        │
│ i64      ┆ str     ┆ f64    ┆ i64      ┆ str        │
╞══════════╪═════════╪════════╪══════════╪════════════╡
│ 101      ┆ Laptop  ┆ 1200.5 ┆ 2        ┆ 2024-01-15 │
│ 102      ┆ Mouse   ┆ 25.99  ┆ 5        ┆ 2024-01-16 │
│ 103      ┆ Keyboard┆ 45.0   ┆ 3        ┆ 2024-01-16 │
│ 104      ┆ Monitor ┆ 350.0  ┆ 1        ┆ 2024-01-17 │
│ 105      ┆ Laptop  ┆ null   ┆ 2        ┆ 2024-01-18 │
└──────────┴─────────┴────────┴──────────┴────────────┘

You can see the last row has a null value for price. That's a missing value we need to handle.


# Show first 3 rows only
print(df.head(3))

shape: (3, 5)
┌──────────┬─────────┬────────┬──────────┬────────────┐
│ order_id ┆ product ┆ price  ┆ quantity ┆ date       │
│ ---      ┆ ---     ┆ ---    ┆ ---      ┆ ---        │
│ i64      ┆ str     ┆ f64    ┆ i64      ┆ str        │
╞══════════╪═════════╪════════╪══════════╪════════════╡
│ 101      ┆ Laptop  ┆ 1200.5 ┆ 2        ┆ 2024-01-15 │
│ 102      ┆ Mouse   ┆ 25.99  ┆ 5        ┆ 2024-01-16 │
│ 103      ┆ Keyboard┆ 45.0   ┆ 3        ┆ 2024-01-16 │
└──────────┴─────────┴────────┴──────────┴────────────┘

Getting Summary Statistics with describe

The describe method provides statistical summaries for numeric columns.

It returns count, mean, standard deviation, min, quartiles, and max. This is invaluable for understanding data distribution.


# Get summary statistics for all numeric columns
print(df.describe())

shape: (7, 6)
┌────────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│ statistic  ┆ order_id ┆ price    ┆ quantity ┆ date     ┆ product  │
│ ---        ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      │
│ str        ┆ f64      ┆ f64      ┆ f64      ┆ str      ┆ str      │
╞════════════╪══════════╪══════════╪══════════╪══════════╪══════════╡
│ count      ┆ 5.0      ┆ 4.0      ┆ 5.0      ┆ 5        ┆ 5        │
│ null_count ┆ 0.0      ┆ 1.0      ┆ 0.0      ┆ 0        ┆ 0        │
│ mean       ┆ 103.0    ┆ 405.3725 ┆ 2.6      ┆ null     ┆ null     │
│ std        ┆ 1.581139 ┆ 545.3475 ┆ 1.516575 ┆ null     ┆ null     │
│ min        ┆ 101.0    ┆ 25.99    ┆ 1.0      ┆ 2024-01-15┆ Keyboard │
│ 25%        ┆ 102.0    ┆ 45.0     ┆ 2.0      ┆ null     ┆ null     │
│ 50%        ┆ 103.0    ┆ 350.0    ┆ 2.0      ┆ null     ┆ null     │
│ 75%        ┆ 104.0    ┆ 1200.5   ┆ 3.0      ┆ null     ┆ null     │
│ max        ┆ 105.0    ┆ 1200.5   ┆ 5.0      ┆ 2024-01-18┆ Monitor  │
└────────────┴──────────┴──────────┴──────────┴──────────┴──────────┘

Look at the null_count row. It shows 1 missing value in price. The mean is calculated only from non-null values.

This is more detailed than pandas' describe because it includes null counts. For comparison, read our Polars vs Pandas: Why Switch? article.

Combining Methods for a Full Picture

Use these methods together for a complete data overview.

Start with shape for size, then dtypes for types, head for samples, and describe for statistics.


# Quick data exploration function
def explore_data(df):
    print("=== SHAPE ===")
    print(df.shape)
    print("\n=== DTYPES ===")
    print(df.dtypes)
    print("\n=== HEAD (3 rows) ===")
    print(df.head(3))
    print("\n=== DESCRIBE ===")
    print(df.describe())

explore_data(df)

=== SHAPE ===
(5, 5)

=== DTYPES ===
[Int64, Utf8, Float64, Int64, Utf8]

=== HEAD (3 rows) ===
shape: (3, 5)
┌──────────┬─────────┬────────┬──────────┬────────────┐
│ order_id ┆ product ┆ price  ┆ quantity ┆ date       │
│ ---      ┆ ---     ┆ ---    ┆ ---      ┆ ---        │
│ i64      ┆ str     ┆ f64    ┆ i64      ┆ str        │
╞══════════╪═════════╪════════╪══════════╪════════════╡
│ 101      ┆ Laptop  ┆ 1200.5 ┆ 2        ┆ 2024-01-15 │
│ 102      ┆ Mouse   ┆ 25.99  ┆ 5        ┆ 2024-01-16 │
│ 103      ┆ Keyboard┆ 45.0   ┆ 3        ┆ 2024-01-16 │
└──────────┴─────────┴────────┴──────────┴────────────┘

=== DESCRIBE ===
shape: (7, 6)
┌────────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│ statistic  ┆ order_id ┆ price    ┆ quantity ┆ date     ┆ product  │
│ ---        ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      │
│ str        ┆ f64      ┆ f64      ┆ f64      ┆ str      ┆ str      │
╞════════════╪══════════╪══════════╪══════════╪══════════╪══════════╡
│ count      ┆ 5.0      ┆ 4.0      ┆ 5.0      ┆ 5        ┆ 5        │
│ null_count ┆ 0.0      ┆ 1.0      ┆ 0.0      ┆ 0        ┆ 0        │
│ mean       ┆ 103.0    ┆ 405.3725 ┆ 2.6      ┆ null     ┆ null     │
│ std        ┆ 1.581139 ┆ 545.3475 ┆ 1.516575 ┆ null     ┆ null     │
│ min        ┆ 101.0    ┆ 25.99    ┆ 1.0      ┆ 2024-01-15┆ Keyboard │
│ 25%        ┆ 102.0    ┆ 45.0     ┆ 2.0      ┆ null     ┆ null     │
│ 50%        ┆ 103.0    ┆ 350.0    ┆ 2.0      ┆ null     ┆ null     │
│ 75%        ┆ 104.0    ┆ 1200.5   ┆ 3.0      ┆ null     ┆ null     │
│ max        ┆ 105.0    ┆ 1200.5   ┆ 5.0      ┆ 2024-01-18┆ Monitor  │
└────────────┴──────────┴──────────┴──────────┴──────────┴──────────┘

Working with Larger Datasets

These methods are fast even on millions of rows. Polars is built for performance.

For reading large files, check our Read & Write Files with Polars guide. It shows how to load data efficiently.

Remember: describe only works on numeric columns by default. For string columns, you need to cast them or use other methods.

Conclusion

Exploring your data is the first step in any analysis. Polars makes it easy with shape, dtypes, head, and describe.

Shape tells you the size. Dtypes reveal column types. Head shows sample rows. Describe gives summary statistics.

Use these four methods together to get a complete picture of your dataset. This helps you spot issues early and plan your analysis better.

Start with these basics, and you'll master Polars data exploration in no time.