polars.from_dataframe#
- polars.from_dataframe(df: Any, *, allow_copy: bool = True) DataFrame [source]#
Build a Polars DataFrame from any dataframe supporting the interchange protocol.
- Parameters:
- df
Object supporting the dataframe interchange protocol, i.e. must have implemented the
__dataframe__
method.- allow_copy
Allow memory to be copied to perform the conversion. If set to False, causes conversions that are not zero-copy to fail.
Notes
Details on the dataframe interchange protocol: https://data-apis.org/dataframe-protocol/latest/index.html
Zero-copy conversions currently cannot be guaranteed and will throw a
RuntimeError
.Using a dedicated function like
from_pandas()
orfrom_arrow()
is a more efficient method of conversion.