Given a dictionary of pandas.Series with numpy.array in each cell,
import pandas as pd
import numpy as np
N = 5
foo = [x for x in np.random.randint(10, size=(N,8))] # list of ndarray
bar = [x for x in np.random.randint(10, size=(N,8))] # list of ndarray
baz = [x for x in np.random.randint(10, size=(N,8))] # list of ndarray
input = {
'foo': pd.Series(foo, index=pd.date_range('2020-01-01', periods=N, freq='D')),
'bar': pd.Series(bar, index=pd.date_range('2020-01-01', periods=N, freq='D')),
'baz': pd.Series(baz, index=pd.date_range('2020-01-01', periods=N, freq='D')),
}
print(input)
# {'foo':
# 2020-01-01 [4, 1, 3, 3, 4, 6, 0, 2]
# 2020-01-02 [7, 7, 1, 2, 1, 2, 8, 6]
# 2020-01-03 [1, 0, 6, 8, 1, 8, 2, 3]
# 2020-01-04 [1, 5, 6, 0, 1, 8, 8, 4]
# 2020-01-05 [4, 7, 9, 3, 5, 3, 0, 1]
# Freq: D, dtype: object,
# 'bar':
# 2020-01-01 [0, 2, 2, 5, 4, 9, 7, 9]
# 2020-01-02 [7, 0, 8, 0, 7, 8, 8, 9]
# 2020-01-03 [6, 7, 2, 7, 2, 9, 8, 7]
# 2020-01-04 [1, 8, 8, 9, 6, 1, 4, 6]
# 2020-01-05 [9, 4, 4, 2, 6, 2, 7, 7]
# Freq: D, dtype: object,
# 'baz':
# 2020-01-01 [9, 2, 9, 2, 5, 3, 5, 3]
# 2020-01-02 [6, 5, 3, 3, 9, 7, 7, 9]
# 2020-01-03 [5, 7, 0, 6, 1, 5, 6, 7]
# 2020-01-04 [3, 9, 2, 6, 1, 5, 9, 9]
# 2020-01-05 [2, 7, 6, 4, 1, 2, 9, 2]
# Freq: D, dtype: object}
What is the most efficient method to convert this into a MultiIndex pandas DataFrame with the dictionary key in the first multi-index level and the series' DateTimeIndex in the second multi-index level?
Using the example given above, the desired pandas DataFrame will have 15 rows and 8 columns