【发布时间】:2019-06-18 20:08:55
【问题描述】:
我将 2 人对话的 15 分钟音频文件发送到转录/演讲者分类服务。情况要求我将 15 分钟的文件分成三个 5 分钟的文件。不幸的是,说话人标签在各个块中不一致,但我需要它们用于分析。
例如,在第一个文件中,扬声器被标记为“0”和“1”。但是,在第二个文件中,它们被标记为“1”和“2”。在第三个文件中,它们可能分别被标记为“1”和“0”。这是一个问题,因为我需要一致的标签。
我目前的方法是表示数据框中每个块的数据。为了获得跨数据帧的标签参考,我将每个数据帧重叠了 10 秒。我想合并“transcript”、“start”和/或“start”列匹配的每个数据框。
然后,我想修改新合并的数据帧上的说话人标签方案,以根据重叠值匹配先前的数据帧。
这是数据框 1 的样子:
df
transcript start stop speaker_label
0 hello world 1.2 2.2 0
1 why hello, how are you? 2.3 4.0 1
2 fine, thank you 4.1 5.0 0
这就是数据框 2 的样子。注意由于重叠,第一行如何匹配上一个数据帧中的最后一行,但现在 speaker_label 方案不同。
df1
transcript start stop speaker_label
0 fine, thank you 4.1 5.0 1
1 you?(should be speaker 0) 5.1 6.0 1
2 good, thanks(should be speaker 1) 6.1 7.0 2
这就是我想要的,数据帧在“start”值匹配的地方垂直合并,并且“df1”“speaker_label”方案与“df”方案匹配。
ideal_df
transcript start stop speaker_label
0 hello world 1.2 2.2 0
1 why hello, how are you? 2.3 4.0 1
2 fine, thank you 4.1 5.0 0
3 you?(should be speaker 0) 5.1 6.0 0
4 good, thanks(should be speaker 1) 6.1 7.0 1
【问题讨论】:
-
pd.concat([df,df1], ignore_index=True).drop_duplicates('transcript')? -
感谢@harvpan,这解决了我加入数据帧的第一个问题。现在我需要在数据帧之间匹配“speaker_label”方案。
标签: python python-3.x pandas