How to convert from pandas to polars dataframe

pl.from_pandas

100DaysOfPolars
Author

Joram Mutenge

Published

2025-07-03

Polars is highly versatile. It can accept a Pandas dataframe and convert it into a Polars dataframe. This conversion is especially useful when working with HTML data, as Polars currently does not support reading directly from HTML.

Reading HTML data with pandas

Yes, it’s possible to read HTML tables using Pandas, just as you would read data from a CSV file.

import pandas as pd

url = 'https://en.wikipedia.org/wiki/List_of_Suits_episodes'

df = (pd.read_html(url)[1]
 [['Title', 'Directed by']]
 .head(4)
 )
df
Title Directed by
0 "Pilot" Kevin Bray
1 "Errors and Omissions" John Scott
2 "Inside Track" Kevin Bray
3 "Dirty Little Secrets" Dennie Gordon

Change from pandas to polars dataframe

The pl.from_pandas expression allows us to turn a Pandas dataframe to a polars dataframe. Here’s how to use it.

import polars as pl

pl.from_pandas(df)
shape: (4, 2)
Title Directed by
str str
""Pilot"" "Kevin Bray"
""Errors and Omissions"" "John Scott"
""Inside Track"" "Kevin Bray"
""Dirty Little Secrets"" "Dennie Gordon"


Make your data analysis work easier by learning how to use Polars in this Polars course