0.12.0
Ubuntu でPandas バージョンを使用してい13.04
ます。条件ごとに分割された EEG データを含む 5D パネル オブジェクトを作成しようとしています。
データを構造化する方法:
の使用方法を示すことから始めましょうpandas.core.panelnd.creat_nd_panel_factory
。
Subject = panelnd.create_nd_panel_factory(
klass_name='Subject',
axis_orders=['setsize', 'location', 'vfield', 'channels', 'samples'],
axis_slices={'labels': 'location',
'items': 'vfield',
'major_axis': 'major_axis',
'minor_axis': 'minor_axis'},
slicer=pd.Panel4D,
axis_aliases={'ss': 'setsize',
'loc': 'location',
'vf': 'vfield',
'major': 'major_axis',
'minor': 'minor_axis'}
# stat_axis=2 # dafuq is this?
)
基本的に、組織は次のとおりです。
setsize
: 実験条件。1
または2
location
: 実験条件、"same"
、"diff"
またはNone
vfield
: 実験条件。"lvf"
または "rvf
"
最後の 2 つの軸は と に対応しDataFrame
ます。わかりやすくするために名前が変更されています。major_axis
minor_axis
channels
: 列、EEG チャネル (129 個)samples
: 行、個々のサンプル。samples
時間軸として考えることができます。
私がやろうとしていること:
各実験条件 ( subject
x setsize
x location
x vfield
) は独自のタブ区切りファイルに保存され、それを で読み込んでオブジェクトpandas.read_table
を取得しDataFrame
ます。各被験者に対して1 つの 5 次元パネル (つまり ) を作成したいと考えていますSubject
。これには、その被験者のすべての実験条件 (つまりDataFrame
s) が含まれます。
まず、subject/ ごとにネストされた辞書を作成しますSubject
。
# ... do some boring stuff to get the text files, etc...
for _, factors in df.iterrows():
# `factors` is a 4-tuple containing
# (subject number, setsize, location, vfield,
# and path to the tab-delimited file).
sn, ss, loc, vf, path = factors
eeg = pd.read_table(path, sep='\t', names=range(1, 129) + ['ref'], header=None)
# build nested dict
subjects.setdefault(sn, {}).setdefault(ss, {}).setdefault(loc, {})[vf] = eeg
# and now attempt to build `Subject`
for sn, d in subjects.iteritems():
subjects[sn] = Subject(d)
完全なスタック トレース
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-2-831fa603ca8f> in <module>()
----> 1 import_data()
/home/louist/Dropbox/Research/VSTM/scripts/vstmlib.py in import_data()
64
65 import ipdb; ipdb.set_trace()
---> 66 for sn, d in subjects.iteritems():
67 subjects[sn] = Subject(d)
68
/usr/local/lib/python2.7/dist-packages/pandas/core/panelnd.pyc in __init__(self, *args, **kwargs)
65 if 'dtype' not in kwargs:
66 kwargs['dtype'] = None
---> 67 self._init_data(*args, **kwargs)
68 klass.__init__ = __init__
69
/usr/local/lib/python2.7/dist-packages/pandas/core/panel.pyc in _init_data(self, data, copy, dtype, **kwargs)
250 mgr = data
251 elif isinstance(data, dict):
--> 252 mgr = self._init_dict(data, passed_axes, dtype=dtype)
253 copy = False
254 dtype = None
/usr/local/lib/python2.7/dist-packages/pandas/core/panel.pyc in _init_dict(self, data, axes, dtype)
293 raxes = [self._extract_axis(self, data, axis=i)
294 if a is None else a for i, a in enumerate(axes)]
--> 295 raxes_sm = self._extract_axes_for_slice(self, raxes)
296
297 # shallow copy
/usr/local/lib/python2.7/dist-packages/pandas/core/panel.pyc in _extract_axes_for_slice(self, axes)
1477 """ return the slice dictionary for these axes """
1478 return dict([(self._AXIS_SLICEMAP[i], a) for i, a
-> 1479 in zip(self._AXIS_ORDERS[self._AXIS_LEN - len(axes):], axes)])
1480
1481 @staticmethod
KeyError: 'location'
これが実験的な機能であることは理解していpanelnd
ますが、何か間違ったことをしていることは確かです。誰かが私を正しい方向に向けることができますか? バグである場合、何か対処法はありますか?
いつものように、よろしくお願いします!