0

How can I use pandas.pivot_table or any other method to split the following data frame into two?

This is my input data frame:

   Method   N    Mean   Max   Min    Median  Mode   Meduim
0   A       5    0.40   0.55  0.25    0.39   N/A    m1
2   A       10   0.26   0.47  0.10    0.25   N/A    m2
1   B       5    0.48   0.62  0.33    0.50   N/A    m1
3   B       7    0.41   0.47  0.36    0.42   0.36   m2

And I want to output the two following data frames

A      m1       m2
N      5        10  
Mean   0.40     0.26  
Max    0.55     0.47  
Min    0.25     0.10    
Median 0.39    0.25   
Mode   N/A      N/A   

and

B      m1      m2
N      5       7
Mean   0.48    0.41  
Max    0.62    0.47  
Min    0.33    0.36    
Median 0.50    0.42  
Mode   N/A     0.36 

Thank you.

3
  • Have you tried anything, can you show us your code ? Commented Aug 6, 2019 at 20:00
  • You don't need pivot. Just transpose your data frame (df.T) and play with it Commented Aug 6, 2019 at 20:02
  • Thank you, I think my fixation with pivot was making it too complicated. Commented Aug 7, 2019 at 11:55

1 Answer 1

1

Is it pivot?

df.set_index(['Method','Meduim']).T

gives:

Method     A            B      
Meduim    m1     m2    m1    m2
N       5.00  10.00  5.00  7.00
Mean    0.40   0.26  0.48  0.41
Max     0.55   0.47  0.62  0.47
Min     0.25   0.10  0.33  0.36
Median  0.39   0.25  0.50  0.42
Mode     NaN    NaN   NaN  0.36
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I think my fixation with pivot was making it too complicated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.