Conversion from/to pandas
Each Terality structure provides two methods that allow you to easily convert pandas objects into terality structures and conversely.
Using from_pandas / from_ndarray methods, all the data will be retrieved in your RAM. If the object size is too important, you may run into a MemoryError.
DataFrame:
@classmethod
terality.DataFrame.from_pandas(df: pandas.DataFrame) -> terality.DataFrame
terality.DataFrame.to_pandas() -> pandas.DataFrame
Series:
@classmethod
terality.Series.from_pandas(series: pandas.Series) -> terality.Series
terality.Series.to_pandas() -> pandas.Series
Index:
@classmethod
terality.Index.from_pandas(index: pandas.Index) -> terality.Index
terality.Index.to_pandas() -> pandas.Index
NDArray:
@classmethod
terality.NDArray.from_ndarray(ndarray: numpy.ndarray) -> terality.NDArray
terality.NDArray.to_ndarray() -> numpy.ndarray
terality.NDArray is meant to be used within pandas methods arguments, the numpy API is not supported by terality. Only 1D arrays are currently implemented.
Using these methods, you can easily make roundtrips between pandas and Terality structures with small amounts of data.
import pandas as pd
import terality as te
pdf = pd.DataFrame(range(100))
tdf = te.DataFrame.from_pandas(pdf)
pdf_round_trip = tdf.to_pandas()
Copy link