iter_by_file()

audformat.utils.iter_by_file(obj)[source]

Iterate over object by file.

Each iteration returns a file and the according sub-object.

Parameters

obj (Union[Index, Series, DataFrame]) – object conform to table specifications

Return type

Iterator[Tuple[str, Union[Index, Series, DataFrame]]]

Returns

iterator in form of (file, sub_obj)

Examples

>>> index = filewise_index(["f1", "f1", "f2"])
>>> next(iter_by_file(index))
('f1', Index(['f1'], dtype='string', name='file'))
>>> index = segmented_index(["f1", "f1", "f2"], [0, 1, 0], [2, 3, 1])
>>> next(iter_by_file(index))
('f1', MultiIndex([('f1', '0 days 00:00:00', '0 days 00:00:02'),
    ('f1', '0 days 00:00:01', '0 days 00:00:03')],
   names=['file', 'start', 'end']))
>>> obj = pd.Series(["a", "b", "b"], index)
>>> next(iter_by_file(obj))
('f1', file  start            end
f1    0 days 00:00:00  0 days 00:00:02    a
      0 days 00:00:01  0 days 00:00:03    b
dtype: object)