Beyond Pandas: When to Use Statsmodels or Pingouin for Statistical Testing in Python

Statsmodels vs Pingouin statistical testing in Python cover image
Python Statistics

Pandas is one of the first Python libraries students learn for data analysis. It is excellent for cleaning, organising and exploring datasets, but it is not designed to handle every statistical test.

When you need correlation, t-tests, ANOVA, regression or detailed statistical modelling, libraries such as Pingouin and Statsmodels become much more useful. This guide shows when to use each, with code you can adapt.

By the Analytivio team9 min readUpdated November 2026

The short answer

Use Pandas to prepare and describe data, Pingouin for common statistical tests such as t-tests, ANOVA, correlation and effect sizes, and Statsmodels when you need regression, detailed model output, diagnostics or time-series analysis.

Pandas is only the beginning

Pandas is extremely useful for importing, cleaning, filtering and organising data. It can also calculate basic descriptive statistics such as means, standard deviations and counts.

However, academic research often requires more than descriptive statistics. For a dissertation, you may need to test relationships between variables, compare groups or determine whether a result is statistically significant.

This is where specialised Python statistical libraries can make your analysis easier.

import pandas as pd
df = pd.read_csv("survey.csv")
print(df.describe())               # means, SDs, min, max
print(df.groupby("gender")["stress"].mean())
print(df[["stress", "sleep"]].corr())  # correlation value only, no p-value

Notice the last line: Pandas gives you the correlation coefficient but not a p-value or confidence interval. That gap is exactly what Pingouin and Statsmodels fill.

When should you use Statsmodels?

Statsmodels is particularly useful for statistical modelling and statistical inference. It supports methods such as ordinary least squares (OLS) regression, logistic regression, generalized linear models, ANOVA and time-series analysis.

One of its biggest strengths is its detailed statistical output. Depending on the model, you can obtain coefficients, standard errors, p-values, confidence intervals, R-squared values and diagnostic information.

This makes Statsmodels particularly useful for academic research, where understanding and reporting statistical results is often as important as making predictions.

import statsmodels.formula.api as smf

model = smf.ols("wellbeing ~ stress + sleep + C(gender)", data=df).fit()
print(model.summary())   # coefficients, SEs, p-values, CIs, R-squared

The formula interface will feel familiar if you have seen R. C(gender) tells Statsmodels to treat gender as a categorical variable rather than a number.

When should you use Pingouin?

Pingouin focuses on making many common statistical procedures straightforward to perform in Python. It supports analyses such as correlation, t-tests, ANOVA, non-parametric tests and effect-size calculations.

For students who are learning statistical testing in Python, Pingouin can be a convenient starting point because many analyses can be performed with relatively simple code.

import pingouin as pg

pg.corr(df["stress"], df["sleep"])                      # r, CI, p-value, power
pg.ttest(df.query("group==1")["score"],
         df.query("group==2")["score"])                # t, df, p, CI, Cohen's d
pg.anova(data=df, dv="score", between="method")        # F, p, partial eta squared
pg.pairwise_tests(data=df, dv="score", between="method", padjust="bonf")

A big advantage for dissertations is that Pingouin reports effect sizes alongside p-values by default, which markers increasingly expect.

Statsmodels vs. Pingouin: What is the difference?

PingouinStatsmodels
Main purposeQuick, readable statistical testsStatistical modelling and inference
Typical analysest-tests, ANOVA, repeated-measures ANOVA, correlation, non-parametric tests, reliabilityOLS, logistic regression, GLMs, mixed models, ANOVA tables, time series
Output styleTidy Pandas DataFrame, one row per testDetailed summary tables and model objects
Effect sizesIncluded by default for many testsUsually calculated separately
DiagnosticsSome assumption tests (normality, sphericity, homoscedasticity)Extensive regression diagnostics
Best forComparing groups and testing relationshipsExplaining an outcome with several predictors

In simple terms, use Pingouin for many common statistical tests and Statsmodels when you need detailed statistical modelling and inference.

Which test, which library?

Research questionSuggested function
Are two variables related?pg.corr() or pg.pairwise_corr()
Do two groups differ?pg.ttest() or pg.mwu() (non-parametric)
Do three or more groups differ?pg.anova(), pg.welch_anova() or pg.kruskal()
Did scores change over time?pg.rm_anova() or pg.friedman()
Is my scale reliable?pg.cronbach_alpha()
Which factors predict an outcome?smf.ols() in Statsmodels
What predicts a yes/no outcome?smf.logit() in Statsmodels
Do I have repeated or nested data?smf.mixedlm() in Statsmodels

SciPy (scipy.stats) also offers many basic tests. It is reliable but returns fewer details, so many students find Pingouin output easier to report.

Experience with Python statistics

In my own experience using Python for data analysis, I initially worked extensively with Pandas for data cleaning and preparation. As I moved towards more advanced analysis, I realised that Python becomes much more powerful when different libraries are used for different purposes.

A practical workflow can be:

  1. Pandas → clean and prepare data
  2. Pingouin / Statsmodels → perform statistical analysis
  3. Matplotlib / Seaborn → visualise results
  4. Interpret findings

This approach is more flexible than trying to use a single Python library for the entire analysis.

Checking assumptions before you test

Whichever library you use, check the assumptions of each test before reporting it. Pingouin includes quick helpers such as pg.normality() and pg.homoscedasticity(). For regression in Statsmodels, look at residual plots and the diagnostics in the summary, and consider robust standard errors if variance is uneven.

pg.normality(data=df, dv="score", group="method")
pg.homoscedasticity(data=df, dv="score", group="method")

# Robust standard errors in Statsmodels
model = smf.ols("score ~ method + hours", data=df).fit(cov_type="HC3")

Reporting Python results in APA style

Python output does not come formatted for a dissertation, so you need to turn it into a clear sentence. For example, from a Pingouin t-test you might write:

Students taught with the active method scored higher (M = 72.4, SD = 8.1) than those taught with lectures (M = 67.9, SD = 9.3), t(118) = 2.83, p = .005, d = 0.52, 95% CI [1.35, 7.65].

The numbers above are an illustration. Always copy values directly from your own output, round them consistently and state the Python and library versions in your methods section.

Which should students learn?

There is no single library that is best for every situation. If you mainly need common statistical tests such as correlations, t-tests or ANOVA, Pingouin is a good option to learn. If your research involves regression, statistical modelling, diagnostics or time-series analysis, Statsmodels is particularly valuable.

For students interested in academic research, a combination of Pandas, Pingouin and Statsmodels can provide a strong foundation for statistical analysis in Python.

SciPy, Pingouin and Statsmodels compared for one test

To see why many students prefer Pingouin for reporting, compare the same one-way ANOVA in three libraries:

from scipy import stats
stats.f_oneway(g1, g2, g3)          # F and p only

import pingouin as pg
pg.anova(data=df, dv="score", between="method")   # F, df, p, partial eta squared

import statsmodels.api as sm
import statsmodels.formula.api as smf
model = smf.ols("score ~ C(method)", data=df).fit()
sm.stats.anova_lm(model, typ=2)    # full ANOVA table

All three give the same F and p-value for the same data. The difference lies in how much extra information you get and how easily it fits into a results table.

Common errors when moving beyond Pandas

  • Running a test on a column that still contains text values or missing data.
  • Forgetting to treat group codes as categories in Statsmodels formulas.
  • Reporting uncorrected p-values after many pairwise comparisons; use the padjust option in Pingouin.
  • Using an older function name from a tutorial; check the documentation for your installed version.
  • Mixing up wide and long data formats; most Pingouin ANOVA functions expect long format.

Getting your data into the right shape

Many testing errors are really data-shape errors. Repeated-measures and mixed designs usually need long data, with one row per participant per time point. Pandas makes the conversion simple:

long_df = df.melt(id_vars="id",
                  value_vars=["score_t1", "score_t2", "score_t3"],
                  var_name="time", value_name="score")
pg.rm_anova(data=long_df, dv="score", within="time", subject="id")

Pingouin and Statsmodels for non-parametric and categorical data

Not every dataset meets the assumptions of parametric tests. Pingouin offers the Mann-Whitney U test (pg.mwu()), the Wilcoxon signed-rank test (pg.wilcoxon()), the Kruskal-Wallis test (pg.kruskal()) and the Friedman test (pg.friedman()), each with an effect size where available. For categorical outcomes, pg.chi2_independence() returns the chi-square test together with Cramér’s V.

When your outcome is binary, such as whether a customer renewed or a student passed, Statsmodels’ logistic regression (smf.logit()) lets you include several predictors and report odds ratios by exponentiating the coefficients. Choosing the test that matches your data type is one of the most common corrections we make in student projects.

import numpy as np
logit_model = smf.logit("passed ~ study_hours + attendance", data=df).fit()
print(np.exp(logit_model.params))   # odds ratios

Visualising your test results

A good figure helps readers understand a test result at a glance. After running a Pingouin or Statsmodels analysis, pair it with a simple Seaborn plot: a box or point plot for group comparisons, a scatterplot with a regression line for relationships. Label axes with units and match figure numbers to your text.

How Analytivio can help with Python statistical analysis

Analytivio is a data analytics consultancy supporting students, researchers and businesses with analysis they can trust and explain. For Python statistics, we can help you:

  • Choose the right test and library for each research question.
  • Write or review your Pandas, Pingouin and Statsmodels code.
  • Check assumptions and fix errors in your models.
  • Turn Python output into clear, correctly formatted results.

We explain every step in plain language, so you understand your results and can defend them to a supervisor, examiner or client. Message us on WhatsApp for a free consultation, or explore our statistical modelling services.

Statsmodels and Pingouin together: a combined workflow

In practice you rarely have to choose only one library. A typical dissertation workflow might use Pingouin to check reliability with Cronbach’s alpha, run correlations between scale scores and compare groups with t-tests or ANOVA. Statsmodels then takes over for the main regression model that tests your hypotheses while controlling for other variables. Because both libraries work directly with Pandas DataFrames, moving between them is simple and the code stays readable. Keep each analysis in a clearly labelled section of your script so a marker can see which library produced which result.

Frequently asked questions

Can Pandas perform statistical tests?

Pandas can perform descriptive and basic statistical calculations, but specialised libraries are more appropriate for many formal statistical tests and models.

Is Statsmodels better than Pingouin?

Not necessarily. Pingouin is convenient for many common statistical tests, while Statsmodels is particularly strong for statistical modelling and detailed inference.

Which Python library is best for statistical analysis?

There is no single best library. Pandas is useful for data preparation, Pingouin for many common tests, and Statsmodels for statistical modelling.

Should students learn Statsmodels or Pingouin?

Students can start with Pingouin for common statistical tests and then learn Statsmodels when they need regression, advanced modelling and more detailed statistical output.

How do I install Pingouin and Statsmodels?

Run pip install pingouin statsmodels in your terminal or Anaconda Prompt. Pingouin installs its required dependencies automatically.

Does Pingouin calculate effect sizes?

Yes. Many Pingouin functions report effect sizes such as Cohen’s d or partial eta squared together with the p-value.

Is Pingouin built on Statsmodels?

Pingouin builds on established scientific libraries, including Pandas, SciPy and Statsmodels, and adds a simpler interface plus extra output such as effect sizes.

Need help with statistics in Python?

Our analysts can build, check and explain your Python analysis, from data cleaning to final results tables ready for your dissertation or report.

Keep reading

This article is general guidance. Library features change between versions, so always check the official documentation for the version you use.

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *