Learn how to explore a DataFrame in GPandas using summary statistics. Describe produces a full statistical overview of numeric columns, while column-level helpers return aggregations as convenient maps.

 

Overview

GPandas provides several statistics helpers:

OperationMethodReturns
Full summaryDescribe()*DataFrame of statistics per numeric column
MeanMean()map[string]float64
SumSum()map[string]float64
Standard deviationStd()map[string]float64
MedianMedian()map[string]float64
MinimumMin()map[string]float64
MaximumMax()map[string]float64
Null countsNullCount()map[string]int
Value frequenciesValueCounts()*DataFrame

Note: Aggregation helpers operate on numeric columns only and ignore null values. Non-numeric columns are skipped.

 


 

Describe

Returns a new DataFrame of summary statistics for the numeric columns, similar to pandas’ df.describe().

 

Function Signature

func (df *DataFrame) Describe() (*DataFrame, error)

 

Statistics Produced

StatisticDescription
countNumber of non-null values
meanArithmetic mean
stdSample standard deviation (ddof=1)
minMinimum value
25%First quartile (linear interpolation)
50%Median (linear interpolation)
75%Third quartile (linear interpolation)
maxMaximum value

The result has a leading statistic column followed by one column per numeric column of the original DataFrame.

 


 

Sample Data

All examples use this employee DataFrame:

Employees DataFrame

NameDepartmentAgeSalary
AliceEngineering3095000
BobSales2555000
CharlieEngineering35105000
DianaSales2862000
EveMarketing3272000
FrankEngineering2788000

 

Setup Code

package main

import (
    "fmt"
    "log"

    "github.com/apoplexi24/gpandas"
)

func main() {
    gp := gpandas.GoPandas{}

    // Create employee DataFrame
    df, _ := gp.DataFrame(
        []string{"Name", "Department", "Age", "Salary"},
        []gpandas.Column{
            {"Alice", "Bob", "Charlie", "Diana", "Eve", "Frank"},
            {"Engineering", "Sales", "Engineering", "Sales", "Marketing", "Engineering"},
            {int64(30), int64(25), int64(35), int64(28), int64(32), int64(27)},
            {95000.0, 55000.0, 105000.0, 62000.0, 72000.0, 88000.0},
        },
        map[string]any{
            "Name":       gpandas.StringCol{},
            "Department": gpandas.StringCol{},
            "Age":        gpandas.IntCol{},
            "Salary":     gpandas.FloatCol{},
        },
    )

    // Examples follow...
}

 


 

Describing a DataFrame

Generate the full statistical summary. Non-numeric columns (like Name and Department) are automatically excluded:

summary, err := df.Describe()
if err != nil {
    log.Fatalf("Describe failed: %v", err)
}
fmt.Println(summary.String())

 

Output

+-----------+--------------------+-------------------+
| statistic | Age                | Salary            |
+-----------+--------------------+-------------------+
| count     | 6                  | 6                 |
| mean      | 29.5               | 79500             |
| std       | 3.6193922141707713 | 19623.96494085739 |
| min       | 25                 | 55000             |
| 25%       | 27.25              | 64500             |
| 50%       | 29                 | 80000             |
| 75%       | 31.5               | 93250             |
| max       | 35                 | 105000            |
+-----------+--------------------+-------------------+
[8 rows x 3 columns]

 

Describe Flow

flowchart LR
    subgraph Input["DataFrame"]
        I[Name, Department,<br/>Age, Salary]
    end

    subgraph Select["Select Numeric"]
        S[Age, Salary]
    end

    subgraph Compute["Compute Per Column"]
        C[count, mean, std,<br/>min, 25%, 50%, 75%, max]
    end

    subgraph Output["Summary DataFrame"]
        O[8 rows x 3 columns]
    end

    I --> S
    S --> C
    C --> O

    style Input fill:#1e293b,stroke:#3b82f6,stroke-width:2px
    style Select fill:#1e293b,stroke:#f59e0b,stroke-width:2px
    style Compute fill:#1e293b,stroke:#8b5cf6,stroke-width:2px
    style Output fill:#1e293b,stroke:#22c55e,stroke-width:2px

 


 

Column Aggregations

Each aggregation helper returns a map keyed by numeric column name. Non-numeric columns are omitted.

fmt.Printf("Mean:   %v\n", df.Mean())
fmt.Printf("Sum:    %v\n", df.Sum())
fmt.Printf("Std:    %v\n", df.Std())
fmt.Printf("Median: %v\n", df.Median())
fmt.Printf("Min:    %v\n", df.Min())
fmt.Printf("Max:    %v\n", df.Max())

 

Output

Mean:   map[Age:29.5 Salary:79500]
Sum:    map[Age:177 Salary:477000]
Std:    map[Age:3.6193922141707713 Salary:19623.96494085739]
Median: map[Age:29 Salary:80000]
Min:    map[Age:25 Salary:55000]
Max:    map[Age:35 Salary:105000]

 

Aggregation Semantics

HelperEmpty/all-null columnSingle value
Mean()NaNthe value
Sum()0the value
Std()NaNNaN (needs ≥ 2 values)
Median()NaNthe value
Min() / Max()NaNthe value

 


 

Null Counts

NullCount() reports the number of null values per column, including non-numeric columns:

fmt.Printf("Nulls: %v\n", df.NullCount())

 

Output

Nulls: map[Age:0 Department:0 Name:0 Salary:0]

Note: Aggregations such as Mean and Sum ignore nulls. For example, a column containing 2.0, null, 4.0 has a Mean of 3 and a Sum of 6.

 


 

ValueCounts

Returns a new DataFrame with the frequency of each unique (non-null) value in a column, ordered by descending count. This is similar to pandas’ df["col"].value_counts().

 

Function Signature

func (df *DataFrame) ValueCounts(column string) (*DataFrame, error)

 

Example

counts, err := df.ValueCounts("Department")
if err != nil {
    log.Fatalf("ValueCounts failed: %v", err)
}
fmt.Println(counts.String())

 

Output

+-------------+-------+
| Department  | count |
+-------------+-------+
| Engineering | 3     |
| Sales       | 2     |
| Marketing   | 1     |
+-------------+-------+
[3 rows x 2 columns]

The result has two columns: the original column (holding the unique values) and a count column with the int64 frequencies. Ties are broken by ascending value, and null values are excluded.

 


 

Error Handling

Common Errors

ErrorCauseSolution
“DataFrame is nil”Operating on nil DataFrameCheck DataFrame initialization
“no numeric columns to describe”Describe() on a DataFrame with no numeric columnsEnsure at least one numeric column exists
“column ‘X’ not found”ValueCounts() on a missing columnVerify the column exists

 

Error Handling Example

summary, err := df.Describe()
if err != nil {
    if strings.Contains(err.Error(), "no numeric columns") {
        log.Fatal("DataFrame has no numeric columns to summarize")
    }
    log.Fatalf("Describe error: %v", err)
}
fmt.Println(summary.String())

 


 

Thread Safety

Statistics operations are thread-safe and read-only:

MethodLock TypeDescription
Describe()RLockRead lock during computation
Mean() / Sum() / Std() / Median() / Min() / Max()RLockRead lock during aggregation
NullCount()RLockRead lock during counting
ValueCounts()RLockRead lock during tabulation

The original DataFrame is never mutated, so these methods are safe to call concurrently.

 


 

Complete Example: Exploratory Analysis

package main

import (
    "fmt"
    "log"

    "github.com/apoplexi24/gpandas"
)

func main() {
    gp := gpandas.GoPandas{}

    df, err := gp.Read_csv_typed("employees.csv", map[string]any{
        "Age":    gpandas.IntCol{},
        "Salary": gpandas.FloatCol{},
    })
    if err != nil {
        log.Fatalf("Failed to load data: %v", err)
    }

    // Statistical overview
    summary, err := df.Describe()
    if err != nil {
        log.Fatalf("Describe failed: %v", err)
    }
    fmt.Println("Summary statistics:")
    fmt.Println(summary.String())

    // Quick aggregations
    fmt.Printf("Average salary: %.2f\n", df.Mean()["Salary"])
    fmt.Printf("Total salary:   %.2f\n", df.Sum()["Salary"])

    // Category breakdown
    byDept, err := df.ValueCounts("Department")
    if err != nil {
        log.Fatalf("ValueCounts failed: %v", err)
    }
    fmt.Println("\nHeadcount by department:")
    fmt.Println(byDept.String())

    // Data quality check
    fmt.Printf("Null counts: %v\n", df.NullCount())
}

 


 

See Also