1
votes

I like to create one correlation table which contains two correlation coefficents. (pearson and spearman)

I know that I can create with df.corr(method='spearman') a correlation table.

Do you know if it's possible that the same table contains the 'pearson' and 'spearman' coefficent? Like the pearson is underneath the spearman coefficent in brackets.

Thank you

For example:

enter image description here

1
Can you provide an example of what you'd like to achieve? Is it a tuple like this: (pearson_coeff, spearman_coeff), for each cell? - Gian Segato
i added an example. But a tuple would be fine too - Pytno

1 Answers

2
votes

Not pretty, but maybe something along these lines:

df = pd.DataFrame(np.random.rand(3,3))                                                
c1 = df.corr()                                                                        
c2 = df.corr(method='spearman')                                                       
corr_df = c1.applymap(lambda x: [x]) + c2.applymap(lambda x: [x])

Output:

                            0                            1                            2
0                  [1.0, 1.0]    [0.5457412669991152, 0.5]   [-0.533894951027147, -0.5]
1   [0.5457412669991152, 0.5]                   [1.0, 1.0]  [-0.9999009746183144, -1.0]
2  [-0.533894951027147, -0.5]  [-0.9999009746183144, -1.0]                   [1.0, 1.0]