I have an 8*4 numpy array with floats (myarray) and would like to transform it into a dictionary of dataframes (and eventually concatenate it into one dataframe) with pandas in python. I'm coming across the error "ValueError: DataFrame constructor not properly called!" though. Here is the way I attempt it:
mydict={}
for i, y in enumerate(np.arange(2015,2055,5)):
for j, s in enumerate(['Winter', 'Spring', 'Summer', 'Fall']):
mydict[(y,s)]=pd.DataFrame(myarray[i,j])
mydict
Any ideas? Thanks!
As requested, some sample data:
array([[ 29064908.33333333, 33971366.66666667, 37603508.33333331,
37105916.66666667],
[ 25424991.66666666, 30156625. , 32103324.99999999,
31705075. ],
[ 26972666.66666666, 28182699.99999995, 30614324.99999999,
29673008.33333333],
[ 26923466.66666666, 27573075. , 28308725. ,
27834291.66666666],
[ 26015216.66666666, 28709191.66666666, 30807833.33333334,
27183991.66666684],
[ 25711475. , 32861633.33333332, 35784916.66666666,
28748891.66666666],
[ 26267299.99999999, 35030583.33333331, 37863808.33333329,
29931858.33333332],
[ 28871674.99999998, 38477549.99999999, 40171374.99999999,
33853750. ]])
and expected output:
2015 2020 2025 2030 2035 2040 2045 2050
Winter 2.9e+07 2.5e+07 2.6e+07 2.6e+07 2.6e+07 2.5e+07 2.6e+07 2.8e+07
Spring 3.3e+07 3.0e+07 2.8e+07 2.7e+07 2.8e+07 3.2e+07 3.5e+07 3.8e+07
Summer 3.7e+07 3.2e+07 3.0e+07 2.8e+07 3.0e+07 3.5e+07 3.7e+07 4.0e+07
Fall 3.7e+07 3.1e+07 2.9e+07 2.7e+07 2.7e+07 2.8e+07 2.9e+07 3.3e+07