Home Using Spacy with Polars?
Post
Cancel

Using Spacy with Polars?

Published on: 13th September 2022

How do third-party libraries work with Polars?

This post was created while writing my Up & Running with Polars course. Check it out here with a free preview of the first chapters

One thing people ask me about switching from Pandas to Polars is working with 3rd party libraries. What if they don’t support Polars?

Often, however, this isn’t much of an issue…

Take the example below with the NLP library Spacy. Here Spacy takes a column from a Polars dataframe in the same way it would take a column from a Pandas dataframe.

1
2
3
4
5
import spacy
nlp = spacy.load("en_core_web_sm")

doc = nlp(df[0,"text"])
spacy.displacy.render(doc, style="ent")

Output of Spacy annotated renderer from Polars input

Why does this work so smoothly? Because many libraries aren’t looking for a pandas dataframe column - they just want an iterable. A pandas column is an iterable, but so is a tuple, list or a polars dataframe column.

Learn more

Want to know more about Polars for high performance data science and ML? Then you can:

or let me know if you would like a Polars workshop for your organisation.

This post is licensed under CC BY 4.0 by the author.