私のデータを操作しようとしていて、何らかの問題に直面している人もいます。私は辞書のリストのように私のデータを配置python new dict値が一致するキーの値が
まず:
data = [{'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'top', 'n' : 1, 'result' : 2.5} , {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'top', 'n' : 2, 'result' : 3.8}, {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'top', 'n' : 3, 'result' : 2.7}, {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'bottom', 'n' : 1, 'result' : 34.2} , {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'bottom', 'n' : 2, 'result' : 38.6}, {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'bottom', 'n' : 3, 'result' : 27.3}]
ご覧のとおり、値を変更するには、オリエンテーション、複製数Nと結果です。
私はこの新しい配列を取得しよう:
arrangeData = [{'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'top', n : [1,2,3], 'result' : [2.5, 3.8, 2.7]}, {'compound' : 'molecule1', 'time' : 18, 'temp' : 20, 'orientation' : 'bottom', n : [1,2,3], 'result' : [34.2, 38.6, 27.3]}]
あなたが推測しているように、辞書の私の本当のデータリストは、時間をいくつかの化合物を含んで、一時
私の最初の愚かな仮定をループにしました
for d in data:
if d[0] == 'molecule1':
if d[1] == 18:
if d[2] == 20
...
ただし、ハードコーディングと全体的に不十分です。すべてのデータは、辞書の私のリストにあるのでそう、だけでなく
for d in data:
for c in compound:
for t in time:
for tp in temp:
for o in orientation:
if d[0] == c:
...
愚か:再び各リストを
compound = ['molecule1', 'molecule2', 'molecule3]
time = [18, 24]
temp = [20, 37]
orientation = ['top', 'bottom']
とループ:次に
は、私はそれぞれの値のリストを使用しようとしています値のリストを導入するのは間違った方法です。
- 私が代わりに辞書の各条件と結果をストックする別の形式を使用する必要があります。ここでは
が質問ありますか?
- dictの値を確認し、データの新しいdict(上記のarrangeDataなど)を作成するにはどうすればよいですか?
EDITまさに私が探してどのようなことを1
おかげハイヴ!あなたはグループ変数にしたいようにそれはそう一例として与えるN 化合物、時間、一時とオリエンテーションの組み合わせのためのと結果arrangeData
から