I have a pandas dataframe. It looks like this:
pd.DataFrame(data=np.arange(1,10).reshape(3,3), index=['A', 'B', 'C'], columns=['A', 'B', 'C'])
but has 100 rows and 100 columns.
I want to flatten it, so that it looks like this:
pd.DataFrame({'row' : ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'], 'col' : ['A', 'B', 'C']*3, 'val' : np.arange(1,10)})
What's the most efficient way to do this?
Thanks,
Jack