Transpose matrix operation before transforming to df