skbio.stats.distance.DistanceMatrix.to_series#
- DistanceMatrix.to_series()[source]#
Create a
pandas.Series
from thisDistanceMatrix
.The series will contain distances in condensed form: only distances from one matrix triangle are included, and the diagonal is excluded. The series’ index will be a
pd.MultiIndex
relating pairs of IDs to distances. The pairs of IDs will be in row-major order with respect to the upper matrix triangle.To obtain all distances (i.e. both upper and lower matrix triangles and the diagonal), use
DistanceMatrix.to_data_frame
. To obtain only the distances in condensed form (e.g. for use with SciPy), useDistanceMatrix.condensed_form
.- Returns:
- pd.Series
pd.Series
with pairs of IDs on the index.
Examples
>>> 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