I am calculating the correlation between columns in a large table using the in-database Python engine in SQL Server 2019 and, since this calculation returns a diagonal matrix, would like to be able to view the results in SSMS with the rows labeled mirroring the column names.
I know the basics of SQL querying, but not much beyond, so maybe I'm not phrasing my searches precisely.
Here is an example of my code:
execute sp_execute_external_script
@language = N'Python',
@script = N'
import pandas as pd
from pandas import DataFrame
df = InputDataSet.corr()
OutputDataSet = df
',
@input_data_1 = N'select GHI ,
MNO,
JKL
from PIVOTED_TIME_ID_MATRIX'
with result sets ((GHI float,
MNO float,
JKL float))
This returns:
***** GHI | MNO | JKL
Row 1 1 0.5 0.5
Row 2 0.5 1 0.5
Row 3 0.5 0.5 1
and I would like to see:
***** GHI | MNO | JKL
GHI 1 0.5 0.5
MNO 0.5 1 0.5
JKL 0.5 0.5 1
Is this possible?