I have a two-dimensional dataframe, for simplicity it looks:
df = Pd.DataFrame ([(1,2.2,5), (2,3, -1)], index = ['row1', 'row2'], column = ["cola 1", "cola 2" , 'Cole 3']) With Output:
col1 col2 col3 row1 1 2.2 5 line 2 2 -2 -3 -1 This is the best way to get values:
Row name's callname value line 2 calls 3 -1 line 1 call 1 1 Line 2 Call 1 2 Line 1 Call 2 2.2 Row 2 Col2 3.0 row1 Col3 5 I tried. Stack (), did not get too far, it is possible by using a loop for nested - but unbearable ..
Any ideas here?
Melt is a reverse unstack
in [6]: DF Out [6]: col1 col2 col3 row1 1 2.2 in 5 rows 2 2 -3 -1 [7]: PD mixed (df.reset_index (), id_vars = 'index') Out [7]: Pointer variable value 0 row1 Col1 1.0 1 row2 col1 2.0 2 row1 col2 2.2 3 row2 col2 3.0 4 row1 col3 5.0 5 line2 col3 -1.0 / code>
No comments:
Post a Comment