def normalize_segment_names(dataframe, inplace=False):
"""
Makes the segment index of the dataframe have names which correspond to the original .mat segment names.
:param dataframe: The dataframe with segment names
:param inplace: If True, the segment index will be changed in place in the given data frame.
:return: A DataFrame where the segment name part of the index has been canonicalized. If inplace is True, the
orignal dataframe is returned, otherwise a copy is returned.
"""
index_values = dataframe.index.get_values()
fixed_values = [(fileutils.get_segment_name(filename), frame) for filename, frame in index_values]
if not inplace:
dataframe = dataframe.copy()
dataframe.index = pd.MultiIndex.from_tuples(fixed_values, names=dataframe.index.names)
return dataframe
评论列表
文章目录