pandas for python はきちんとしています。辞書のリストを pandas-dataframe に置き換えようとしています。ただし、for ループで値を行ごとに簡単に変更する方法があるのではないかと思っています。
パンダ以外の辞書バージョンは次のとおりです。
trialList = [
{'no':1, 'condition':2, 'response':''},
{'no':2, 'condition':1, 'response':''},
{'no':3, 'condition':1, 'response':''}
] # ... and so on
for trial in trialList:
# Do something and collect response
trial['response'] = 'the answer!'
...そして、それを参照trialList
するため、更新された値が含まれるようになりましtrial
た。とても便利な!しかし、辞書のリストは非常に不便です。特に、パンダが得意とする列単位のものを計算できるようにしたいからです。
したがって、上記のtrialListが与えられたので、パンダのようなことをすることでさらに改善できると思いました:
import pandas as pd
dfTrials = pd.DataFrame(trialList) # makes a nice 3-column dataframe with 3 rows
for trial in dfTrials.iterrows():
# do something and collect response
trials[1]['response'] = 'the answer!'
...しかし、trialList
ここでは変更されません。おそらくdict-versionと同等の、行ごとに値を更新する簡単な方法はありますか? これは、参加者に多くの試行が提示され、各試行でさまざまなデータが収集される実験のためであるため、行ごとであることが重要です。