0

I have a data frame with a single column of values and an index of sample names:

>>> df = pd.DataFrame(data={'value':[1,3,4]},index=['cat','dog','bird'])
>>> print(df)
         value
cat       1
dog       3
bird      4

I would like to convert this to a square matrix wherein each cell of the matrix shows the difference between every set of two values:

      cat    dog   bird
cat     0     2      3
dog     2     0      1
bird    3     1      0

Is this possible? If so, how do I go about doing this?

I have tried to use scipy.spatial.distance.squareform to convert my starting data frame into a matrix, but apparently what I am starting with is not the right type of vector. Any help would be much appreciated!

jtweeder
  • 751
  • 3
  • 19
Kellen
  • 1
  • Can you provide more detail like an example of the dataframe input, the desired output, the code you've tried to use so far, and if the code didn't work the errors or incorrect output you are receiving. – Matthew Barlowe Oct 25 '19 at 03:02
  • Possible duplicate of [Pandas - Creating Difference Matrix from Data Frame](https://stackoverflow.com/questions/46266633/pandas-creating-difference-matrix-from-data-frame) – jtweeder Oct 25 '19 at 11:52

0 Answers0