fabee
fabee

Reputation: 545

Pairing data in python pandas

For example, if the following is the data in pandas:

import pandas as pd

data = {'type': ['cat2','cat1','cat2','cat1','cat2',
                 'cat1','cat2','cat1','cat1','cat2'], 
        'values': [1,2,3,1,2,3,1,2,3,5], 
        'experiment': [0,0,1,1,2,2,3,3,4,4]}
my_data = pd.DataFrame(data)

A paired test is needed between 'cat1' vs. 'cat2' by pairing the data according to 'experiment'. What is the proper way in pandas to do so? I am new to pandas and haven't fully adjusted to thinking about data there.

Upvotes: 1

Views: 965

Answers (1)

elyase
elyase

Reputation: 40963

Is this what you want?:

>>> my_data.pivot(index='experiment', columns='type', values='values')


type        cat1  cat2
experiment            
0              2     1
1              1     3
2              3     2
3              2     1
4              3     5

Upvotes: 2

Related Questions