Align datasets

Shows how to combine information from two datasets describing the same cases, but not necessarily in the same order.

# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
import random
import string

from eelbrain import *


# Generate a dataset with known sequence
ds = Dataset()
ds['ascii'] = Factor(string.ascii_lowercase)
# Add an index variable to the dataset to later identify the cases
ds.index()

# Generate two shuffled copies of the dataset (and print them to confirm that
# they are shuffled)
ds1 = ds[random.sample(range(ds.n_cases), 15)]
ds1.head()
# ascii index
0 t 19
1 x 23
2 y 24
3 l 11
4 n 13
5 u 20
6 q 16
7 g 6
8 a 0
9 d 3


# ascii index
0 m 12
1 o 14
2 b 1
3 y 24
4 s 18
5 v 21
6 a 0
7 p 15
8 w 22
9 j 9


Align the datasets

Use the "index" variable added above to identify cases and align the two datasets

ds1_aligned, ds2_aligned = align(ds1, ds2, 'index')

# show the ascii sequences for the two datasets next to each other to
# demonstrate that they are aligned
ds1_aligned['ascii_ds2'] = ds2_aligned['ascii']
ds1_aligned
# ascii index ascii_ds2
0 t 19 t
1 y 24 y
2 q 16 q
3 a 0 a
4 d 3 d
5 k 10 k
6 m 12 m
7 j 9 j
8 v 21 v


Gallery generated by Sphinx-Gallery