skbio.stats.distance.DistanceMatrix.to_series¶
- DistanceMatrix.to_series()[源代码]¶
创建
pandas.Series
从这个开始DistanceMatrix
。状态:从0.5.1开始试验。
该系列将以压缩形式包含距离:仅包括距一个矩阵三角形的距离,不包括对角线。该系列的索引将是
pd.MultiIndex
将ID对与距离相关联。ID对将相对于上矩阵三角形以行为主的顺序排列。要获得所有距离(即上、下矩阵三角形和对角线),请使用
DistanceMatrix.to_data_frame
。为了获得 only 以缩写形式表示的距离(例如,与本网站一起使用),使用DistanceMatrix.condensed_form
。- 返回:
pd.Series
索引上有成对的ID。- 返回类型:
pd.Series
示例
>>> from skbio import DistanceMatrix >>> dm = DistanceMatrix([[0, 1, 2, 3], ... [1, 0, 4, 5], ... [2, 4, 0, 6], ... [3, 5, 6, 0]], ids=['a', 'b', 'c', 'd']) >>> dm.to_series() a b 1.0 c 2.0 d 3.0 b c 4.0 d 5.0 c d 6.0 dtype: float64