DataFrame mit MultiIndex zum Diktieren
Ich habe einen Datenrahmen mit einem MultiIndex. Ich frage mich, ob ich den Datenrahmen korrekt erstellt habe (siehe unten).
01.01 02.01 03.01 04.01
bar total1 40 52 18 11
total2 36 85 5 92
baz total1 23 39 45 70
total2 50 49 51 65
foo total1 23 97 17 97
total2 64 56 94 45
qux total1 13 73 38 4
total2 80 8 61 50
df.index.values
Ergebnisse in:
array([('bar', 'total1'), ('bar', 'total2'), ('baz', 'total1'),
('baz', 'total2'), ('foo', 'total1'), ('foo', 'total2'),
('qux', 'total1'), ('qux', 'total2')], dtype=object)
df.index.get_level_values
Ergebnisse in:
<bound method MultiIndex.get_level_values of MultiIndex(levels=[[u'bar', u'baz', u'foo', u'qux'], [u'total1', u'total2']],
labels=[[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]],names=[]
Ich versuche letztendlich, das df in ein Wörterbuchdiktat umzuwandeln, so dass der erste Diktatschlüssel eines von ['bar', 'baz', 'foo', 'qux'] ist und die Werte die Daten und das innere Wörterbuch sind gemacht aus 'total1' und 'totals2' als Schlüssel und die Werte sind die ganzen Zahlen des df. Eine alternative Erklärung ist zum Beispiel, wenn dict1 das Diktat ist, dann rufe auf:
dict1['bar']
would in der Ausgabe führen:
{u'bar':{'01.01':{'total1':40,'total2':36},'02.01':{'total1':52,'total2':85},'03.01':{'total1':18,'total2':5},'04.01':{'total1':11,'total2':92} } }
Wie und was müsste ich ändern, um dies zu erreichen? Ist das ein Indizierungsproblem?