0

I need to change below dataframe:

input

I want the output in below form:

OUTPUT

I tried to use itertools.combinations_with_replacement to get all combination

from itertools import combinations_with_replacement comb = list(combinations_with_replacement(pairwise_similarity_df.index,2))

matrix is 10000*10000 so i expected 100000000 rows but got only 50005000.

how can i convert this to required format?

pc94
  • 45
  • 6
  • Does this answer your question? [pandas convert some columns into rows](https://stackoverflow.com/questions/28654047/pandas-convert-some-columns-into-rows) – gionni Mar 04 '21 at 07:21
  • @gionni yes after some modifications it worked..thanks – pc94 Mar 04 '21 at 09:51

1 Answers1

0

Thanks Gionni,

Below code worked for me:

df['company1']=df.index

df=df.melt(id_vars["company1"],var_name="company2")

enter image description here

pc94
  • 45
  • 6