Mam pandas DataFrame z 2 indeksami. (MultiIndex) Chcę wydobyć matrycę Numpy z czymś takim jak df.as_matrix(...)
, ale ta macierz ma kształt (n_rows, 1)
. Chcę matrycy kształtu (n_index1_rows, n_index2_rows, 1)
.Pandas DataFrame z MultiIndex na Numpy Matrix
Czy istnieje sposób użycia .groupby(...)
, a następnie .values.tolist()
lub .as_matrix(...)
, aby uzyskać pożądany kształt?
EDIT: Dane
value
current_date temp_date
1970-01-01 00:00:01.446237485 1970-01-01 00:00:01.446237489 30.497100
1970-01-01 00:00:01.446237494 9.584300
1970-01-01 00:00:01.446237455 10.134200
1970-01-01 00:00:01.446237494 7.803683
1970-01-01 00:00:01.446237400 10.678700
1970-01-01 00:00:01.446237373 9.700000
1970-01-01 00:00:01.446237180 15.000000
1970-01-01 00:00:01.446236961 12.928866
1970-01-01 00:00:01.446237032 10.458800
Jest to rodzaj idei:
np.array([np.resize(x.as_matrix(["value"]).copy(), (500, 1)) for (i, x) in df.reset_index("current_date").groupby("current_date")])
Chcesz tablicę 3D? A może tylko tablica 2D zawierająca indeks i kolumnę? –
Tablica 3D. Wszystkie wartości w zbiorze np.array powinny być wartościami kolumny (nie indeksami). –
Czy możesz podać niektóre przykładowe dane z żądanymi danymi wyjściowymi? – Alexander