datawrangler.zoo.array
- datawrangler.zoo.array.is_array(x)[source]
Return True if and only if is an Array, or a file that can be loaded into an Array.
Parameters
- param x:
an object, file path or URL
Returns
- return:
whether (or not) x is an array (or if it points to an array)
- datawrangler.zoo.array.wrangle_array(data, return_model=False, backend=None, **kwargs)[source]
Turn an Array into a DataFrame (pandas or Polars)
Parameters
- param data:
an Array (or path to an Array)
- param return_model:
if True, return a function for casting an Array into a DataFrame (along with the resulting DataFrame). Default: False
- param backend:
str, optional The DataFrame backend to use (‘pandas’ or ‘polars’). If None, uses the default backend (pandas)
- param kwargs:
a list of keyword arguments: - ‘model’: a callable function or constructor, or a dictionary containing the following keys:
‘model’: a callable function or constructor
‘args’: a list of arguments to pass to the function (in addition to data)
‘kwargs’: a list of keyword arguments to pass to the function
default: pandas.DataFrame or polars.DataFrame (based on backend)
all other keyword arguments are passed to the model (or constructor). These can be used to change how the DataFrame is created (e.g., passing columns=[‘one’, ‘two’, ‘three’] will change the column names of the resulting DataFrame).
Returns
- return:
The resulting DataFrame (pandas or Polars based on backend)
Examples
>>> import numpy as np >>> import datawrangler as dw >>> # Create pandas DataFrame from array (default) >>> df_pandas = dw.wrangle(np.array([1, 2, 3])) >>> # Create Polars DataFrame from array >>> df_polars = dw.wrangle(np.array([1, 2, 3]), backend='polars') >>> # Create DataFrame with custom column names >>> df_custom = dw.wrangle([[1, 2], [3, 4]], array_kwargs={'columns': ['A', 'B']})