Skip to content

Convert categorical operations from pandas to Polars#7

Merged
ugohuche merged 3 commits into
mainfrom
migrate-categorical-to-polars
Jul 16, 2026
Merged

Convert categorical operations from pandas to Polars#7
ugohuche merged 3 commits into
mainfrom
migrate-categorical-to-polars

Conversation

@meshackamadi

Copy link
Copy Markdown
Collaborator

Summary

This PR migrates categorical data examples from pandas to Polars and updates the accompanying explanations to better reflect Polars' API and behavior.

Changes

  • Replaced pandas categorical operations with Polars equivalents.
  • Updated examples to use pl.Enum for ordered categorical data.
  • Improved explanations of category operations in Polars.
  • Added examples demonstrating:
    • value_counts()
    • retrieving Enum categories with .dtype.categories
    • including zero-count categories using a join
    • mode() on Enum columns
  • Updated examples to follow current Polars idioms.
  • Corrected documentation to reflect Polars' stricter handling of Enum categories.

Notes

  • value_counts() only returns categories that are present in the data.
  • Added an example showing how to include unused categories by joining the Enum category list with observed counts.
  • Removed pandas-specific categorical behavior that does not have a direct Polars equivalent.

@meshackamadi meshackamadi requested a review from ugohuche July 16, 2026 20:45
@ugohuche ugohuche merged commit 2349826 into main Jul 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants