Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

transform a square matrix into column wise matrix using pandas

$
0
0

I'm new to python. I have a square matrix and want to transform it to a column wise matrix using pandas dataframe. Its a fairly large matrix 1,000 x 1,000. An example below of what I need. I'm stumped! Any help greatly appreciated - thanks!!!

import pandas as pd# square matrixdata = {'Zone': ['Z1', 'Z2', 'Z3'],'Z1': [10, 3, 1],'Z2': [2, 5, 1],'Z3': [1, 2, 5]}df_square = pd.DataFrame(data)print(df_square)# this is what I need to generatedata = {'Origin_zone': ['Z1', 'Z1', 'Z1', 'Z2', 'Z2', 'Z2', 'Z3', 'Z3', 'Z3'],'Destination_zone': ['Z1', 'Z2', 'Z3', 'Z1', 'Z2', 'Z3', 'Z1', 'Z2', 'Z3'],'Value': [10, 3, 1, 2, 5, 1, 1, 2, 5]          }df_column = pd.DataFrame(data)print(df_column)

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>