I have a dataset with stock price history that I have run a correlation matrix on in pandas. I have unstacked the correlation matrix and filtered it to remove duplicates/redundant values and sorted it like so.
corr_pairs = corr_matrix.unstack().drop_duplicates().sort_values(kind='quicksort')
corr_pairs = corr_pairs[corr_pairs < 1]
print('Sorted Pairs: ')
print(corr_pairs)
Sorted Pairs:
tsla meta 0.709581
googl meta 0.816701
tsla googl 0.916947
Now I wish to extract the names of the stocks that had the highest correlation in the set and assign them to variables such as stock1 and stock2. If I do corr_pairs[-1] this will produce the value for the highest correlation, I need the names of the stocks that have the highest correlation, in this case, tsla and googl.
Thank you to anyone who knows what to do! Appreciate the help!