aixd.data.utils_data.convert_to
- aixd.data.utils_data.convert_to(data: pd.DataFrame | np.ndarray | List[List] | Dict | List[Dict] | torch.Tensor, format: str = 'df', dataobjects: List[DataObject] = None) pd.DataFrame | np.ndarray | List[List] | Dict | List[Dict] | torch.Tensor [source]
Takes any data format, detect the type, and convert it if neccessary.
The possible formats are:
“dict” : dictionary
“dict_list” : list of dictionaries
“df_per_obj” : dataframe
“df” : standard dataframe flattened, all cells contain single values and column names are renamed.
“array” : nparray
“torch” : torch tensor
“list” : nested list
In principle, the only inputs are the data, the desired format and the data objects. This is all required to detect and then convert
Important: this functions only works with the data. This means it does not expect any “uid” or “error” columns. These will cause errors.
- Parameters:
data (Union[pd.DataFrame, np.ndarray, List[List], Dict, List[Dict], torch.Tensor]) – Data with some specific format.
format (str, optional, default=”df”) – Desired target format.
dataobjects (List[DataObject], optional, default=None) – List of data objects from which names and dimensions will be recovered.
- Returns:
data_out (Union[pd.DataFrame, np.ndarray, List[List], Dict, List[Dict], torch.Tensor]) – Converted data