# klib bundles the cleaning and exploratory plots a data scientist writes every time

> klib is a Python library of customised functions for importing, cleaning, analysing and preprocessing tabular data, with a describe module for categorical plots, correlation matrices and distributions, a clean module that drops duplicates and empty rows, standardises column names and converts dtypes, and an interactive Plotly correlation view. It is MIT licensed, built on pandas, and supports Python 3.10 through 3.14.

**akanz1/klib** — Easy to use Python library of customized functions for cleaning and analyzing data.

- Repository: https://github.com/akanz1/klib
- Website: https://medium.com/p/97191d320f80
- Stars: 523 · Forks: 57
- Language: Python
- License: MIT
- Published: 2026-10-22 · Updated: 2026-10-22 · Language: en
- Canonical page: https://hysenlabs.com/projects/akanz1-klib

## What the library is for

klib is described as a Python library for importing, cleaning, analyzing and preprocessing data, and the repository description calls it an easy to use Python library of customized functions for cleaning and analyzing data.

The phrase customised functions is the key to what kind of project this is. These are not new algorithms. They are the functions a data scientist writes for themselves on the third or fourth dataset of a week and then copies from the previous project, with the same behaviour every time because copying is easier than rewriting.

The README is unusually open about where to read about it. Explanations on key functionalities can be found on Medium and Towards Data Science under the author's name, and in the examples section of the repository. There are also introductions and overviews on PythonBytes and on the Data Professor YouTube channel, which tells you the project has reached the point of being covered by the wider Python ecosystem rather than only by its own users.

The topics list gives the scope: data-analysis, data-cleaning, data-preprocessing, data-science, data-visualization, feature-selection, klib and python. Feature selection is the one that is not obvious from the function names, and it comes from the pooling and missing-value handling rather than from a separate module.

The primary language is Python, the licence is MIT, the homepage is a Medium post, and the last push was on 2026-09-01, with the most recent release v1.4.1 from 2026-06-18 after v1.4.0 in February 2026 and v1.3.1 in July 2024.

## Installing it, and what it pulls in

Installation is pip, and the readme asks for an upgrade flag:

```bash
pip install -U klib
```

There is also a conda-forge route:

```bash
conda install -c conda-forge klib
```

The dependency list in pyproject.toml is the honest measure of what the library depends on. Jinja2 at 3.1.0 or later is there for templating, which is how the correlation and distribution plots are rendered. Matplotlib at 3.9.0 or later and seaborn at 0.13.0 or later do the static plotting. NumPy at 2.0.0 or later and SciPy at 1.14.0 or later cover the numeric work. Pandas is the data model itself, with a deliberately wide range of pandas >=1.4,<4.0 so klib keeps working across the pandas 2.x boundary. Plotly at 5.24.0 or later provides the interactive plots.

One dependency deserves comment. screeninfo at 0.8.1 or later is a small library that reports screen size and resolution, and it is the kind of dependency that should not appear in a data library without explanation. Its presence here is almost certainly tied to the interactive plotly output, where a figure has to be rendered at a sensible size for the display it is opened on.

The Python requirement is 3.10 or later, and the classifiers list 3.10 through 3.14, so the project is tracking new Python releases. The build backend is hatchling, and the package is built from a src/ directory with a pyproject.toml and a uv.lock for dependency resolution.

The development toolchain is listed separately as a dependency group: pytest with pytest-cov, mypy, ruff, pre-commit, pydocstyle with the numpy convention, and the notebook tooling ipykernel and nbformat, which are there for the example notebooks rather than for the library itself.

## The describe module: the plots you write every time

The usage section lists the functions under two headings, and the first is the visualisation group.

klib.cat_plot(df) returns a visualisation of the number and frequency of categorical features. klib.corr_mat(df) returns a colour-coded correlation matrix, and klib.corr_plot(df) returns a colour-coded heatmap, ideal for correlations. klib.corr_interactive_plot(df, split="neg").show() returns an interactive correlation plot using plotly. klib.dist_plot(df) returns a distribution plot for every numeric feature. And klib.missingval_plot(df) returns a figure containing information about missing values.

That is six functions covering the four questions you ask of an unfamiliar dataset: what categories are there and how common, how do the features relate, what do the distributions look like, and where are the gaps.

The examples show that these are configurable rather than fixed. The correlation plot takes a split argument, so klib.corr_plot(df, split='pos') displays only positive correlations and split='neg' only negative ones, and the documentation notes that other settings include threshold and cmap. It also takes a target argument, so klib.corr_plot(df, target='wine') shows the correlations with a chosen feature column, which is the version you want when you are deciding what predicts your target.

The missing value plot is described as the default representation of missing values in a DataFrame, with plenty of settings available. The categorical plot takes top and bottom counts, so klib.cat_plot(data, top=4, bottom=4) shows the four most and four least common values in each categorical column, which is how you find the rare levels that will break a model later.

The distribution plot likewise has settings including fill_range and histogram.

One detail about the interactive plot is worth knowing. It returns a Plotly Graph Object Figure, so it supports the update_layout chain method, and klib.corr_interactive_plot(wine, split="neg").update_layout(template="simple_white") is the documented example. It also accepts additional Plotly heatmap graph object keyword arguments, such as zmax in klib.corr_interactive_plot(df, split="neg", zmax=0), which is how you pin the colour scale so two plots are comparable.

## The clean module, and what each step does

The cleaning functions are the part of the library that changes your data rather than showing it to you, and the readme is precise about which ones are steps inside the others.

klib.data_cleaning(df) performs the datacleaning, dropping duplicates and empty rows and columns and adjusting dtypes. klib.clean_column_names(df) cleans and standardizes column names, and it is also called inside data_cleaning(). klib.convert_datatypes(df) converts existing to more efficient dtypes, also called inside data_cleaning(). And klib.drop_missing(df) drops missing values, also called in data_cleaning().

So data_cleaning() is a pipeline of the other functions, and calling the individual functions directly lets you apply one step without the others. That matters because the automatic steps are opinions. Cleaning column names is convenient until you have a column name that the cleaner mangles in a way your downstream code does not expect, and dropping missing values is rarely right in a health or survey dataset where absence is itself a recorded value.

Two functions do something less common. klib.mv_col_handling(df) drops features with a high ratio of missing values, based on informational content rather than on a fixed threshold, which is a more careful rule than dropping any column that is mostly empty. And klib.pool_duplicate_subsets(df) pools a subset of columns based on duplicates with minimal loss of information, which is a feature-engineering operation rather than a cleaning one: if two columns carry the same signal, one of them can go.

The examples section of the repository is where these are demonstrated, with applications of the functions in klib.clean() given in detail. The two notebooks in the examples directory are klib_data_cleaning.ipynb, which is the one to read for the cleaning behaviour, and klib-plots.ipynb for the visualisation side. The examples directory also holds an NFL_DATASET.csv and a datasets/ folder, so you can run them without supplying your own data.

## Where klib fits, and where it stops

The comparison worth making is with writing the same code yourself and with a full analysis framework.

Against writing it yourself, the difference is consistency across projects. A correlation heatmap with a positive-correlation filter and a sensible colour map takes an afternoon to get right once, and then it is wrong in every new notebook because the threshold is a magic number you forgot. A library that gives you the same figure every time removes a class of small inconsistencies that are hard to notice and easy to regret.

Against a full analysis framework, the difference is that klib does not try to be a pipeline. It has no notion of a project, no configuration file describing where data lives and what to do with it, and no run log. It is a toolbox, not a system.

The limits follow from that. Most of what klib provides is interactive exploration, which is valuable at the start of an analysis and less useful when you need the same steps to run unattended every night. The cleaning functions do mutate your frame, and the automatic ones are opinionated, so you need to know what data_cleaning() did before you accept its output. The dependency floor is high too: numpy 2.0, scipy 1.14, matplotlib 3.9, seaborn 0.13, plotly 5.24 and pandas between 1.4 and 4.0, which is a fairly recent stack to require and will not install into an older pinned environment without conflict.

The project itself is well maintained, which is worth saying. The badges show a Flake8 and PyTest workflow, a SonarCloud quality gate, a Scrutinizer quality score and codecov coverage, and the dev toolchain includes ruff, mypy, pydocstyle on the numpy convention, pre-commit and pytest-cov with a coverage configuration that omits tests and version files. There is a .pre-commit-config.yaml and a Makefile with targets for locking dependencies with uv, creating a virtual environment, and running pre-commit on all files.

The Makefile targets are modern: it installs uv through the official install script, creates the environment with a pinned Python 3.13, and syncs with --frozen and --all-extras. The uv.lock file at the root means dependency resolution is reproducible, which is more than most small libraries bother with.

And the documentation strategy is unusual in a good way. Instead of a reference manual, the explanation lives in Medium articles, a podcast episode and a video, with the notebooks doing the rest. For a library whose value is visual, that is arguably the right medium, though it does mean the docs live outside the repository and can drift from the code.

## Conclusion

klib suits a working data scientist who wants the same exploratory and cleaning plots for every new dataset without rewriting them, since the functions take a DataFrame and return a figure or a cleaned frame rather than requiring configuration. It is the wrong tool if you need reproducible pipelines, because most of what it provides is interactive visualisation rather than transform logic you would put in a script, and it is the wrong tool if you are on a pandas version outside the supported range or Python below 3.10. Before you adopt it, run the two notebooks in the examples directory, klib-plots.ipynb and klib_data_cleaning.ipynb, because they show the output of each cleaning function rather than only its signature.

## FAQ

### What is klib?

It is a Python library for importing, cleaning, analyzing and preprocessing data, described as an easy to use library of customized functions. Explanations of the key functionality are published on Medium and Towards Data Science under the author's name, and in the examples section of the repository, with further overviews on PythonBytes and on YouTube.

### How do I install klib?

Run pip install -U klib, or conda install -c conda-forge klib for the conda-forge build. It requires Python 3.10 or later, with classifiers covering 3.10 through 3.14, and it depends on pandas, numpy, scipy, matplotlib, seaborn, plotly, Jinja2 and screeninfo.

### Which plotting functions does klib provide?

cat_plot for the number and frequency of categorical features, corr_mat for a colour-coded correlation matrix, corr_plot for a colour-encoded correlation heatmap, corr_interactive_plot for a Plotly version, dist_plot for a distribution of every numeric feature, and missingval_plot for information about missing values. The correlation plots accept a split argument for positive or negative correlations and a target argument for one feature column.

### What does klib.data_cleaning() do, and can I run the steps separately?

data_cleaning() performs the cleaning, dropping duplicates and empty rows and columns and adjusting dtypes, and it calls the other functions internally: clean_column_names() standardizes column names, convert_datatypes() converts to more efficient dtypes and drop_missing() drops missing values. Calling those three directly applies a single step without the rest.

### Does klib remove columns with too many missing values?

mv_col_handling(df) drops features with a high ratio of missing values based on informational content, rather than on a fixed threshold. A separate function, pool_duplicate_subsets(df), pools a subset of columns based on duplicates with minimal loss of information.

### How is klib tested and developed?

The project uses pytest with pytest-cov and a coverage configuration that omits test and version files, plus ruff, mypy, pydocstyle on the numpy convention and pre-commit. The Makefile targets lock dependencies with uv, create a virtual environment on Python 3.13 and run pre-commit, and there is a uv.lock file at the root.

## Sources

- [akanz1/klib on GitHub](https://github.com/akanz1/klib)
- [License: MIT](https://github.com/akanz1/klib/blob/main/LICENSE)
- [Project website](https://medium.com/p/97191d320f80)
- [README](https://github.com/akanz1/klib/blob/main/README.md)
- [Releases](https://github.com/akanz1/klib/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/akanz1-klib
