segmented_index()¶
- audformat.segmented_index(files=None, starts=None, ends=None)[source]¶
Create segmented index.
Index is conform to table specifications.
If a non-empty index is created and
starts
is set toNone
, the level will be filled up with0
. If a non-empty index is created andends
is set toNone
, the level will be filled up withNaT
.- Parameters
files (
Union
[str
,Sequence
[str
],Index
,Series
,None
]) – set confidence values only on a sub-set of filesstarts (
Union
[float
,int
,str
,Timedelta
,Sequence
[Union
[float
,int
,str
,Timedelta
]],Index
,Series
,None
]) – segment start positions. Time values given as float or integers are treated as secondsends (
Union
[float
,int
,str
,Timedelta
,Sequence
[Union
[float
,int
,str
,Timedelta
]],Index
,Series
,None
]) – segment end positions. Time values given as float or integers are treated as seconds
- Return type
- Returns
segmented index
- Raises
ValueError – if created index contains duplicates
ValueError – if
files
,start
andends
differ in size
Examples
>>> segmented_index("a.wav", 0, 1.1) MultiIndex([('a.wav', '0 days', '0 days 00:00:01.100000')], names=['file', 'start', 'end']) >>> segmented_index("a.wav", "0ms", "1ms") MultiIndex([('a.wav', '0 days', '0 days 00:00:00.001000')], names=['file', 'start', 'end']) >>> segmented_index(["a.wav", "b.wav"]) MultiIndex([('a.wav', '0 days', NaT), ('b.wav', '0 days', NaT)], names=['file', 'start', 'end']) >>> segmented_index(["a.wav", "b.wav"], [None, 1], [1, None]) MultiIndex([('a.wav', NaT, '0 days 00:00:01'), ('b.wav', '0 days 00:00:01', NaT)], names=['file', 'start', 'end']) >>> segmented_index( ... files=["a.wav", "a.wav"], ... starts=[0, 1], ... ends=pd.to_timedelta([1000, 2000], unit="ms"), ... ) MultiIndex([('a.wav', '0 days 00:00:00', '0 days 00:00:01'), ('a.wav', '0 days 00:00:01', '0 days 00:00:02')], names=['file', 'start', 'end'])