Here is my question:
I have some 2-D array data which represent the concentration of some chemical of each grid by the time, like follows:
http://i12.tietuku.com/4501009ea445c286.png .
I want to extract the data of each grid from the 2-D arrays and save each one into a independent DataFrames follow the time series.
How to make this loop process simple? For example:
Input data:
K1 = np.random.rand(50,50),
K2 = np.random.rand(50,50),
.
.
.
.
.
.
.
Kn = np.random.rand(50,50).
Aim:
f1 = [K1[0,0],K2[0,0], K3[0,0] ..... Kn[0,0]]
f2 = [K1[0,1],K2[0,1], K3[0,1] ..... Kn[0,1]]
.
.
.
.
f2500 = [K1[49,49],K2[49,49], K3[49,49] ..... Kn[49,49]]
It looks you might be better off just create one dataframe, with f1, f2, f3 being different columns:
In [9]:
K1 = np.random.rand(50,50)
K2 = np.random.rand(50,50)
K3 = np.random.rand(50,50)
K_list = [K1, K2, K3]
In [10]:
df = pd.DataFrame(np.vstack([item.ravel() for item in K_list]).T,
columns=['f1','f2','f3'],
index=pd.date_range(start='1900-01-01', periods=2500))
print df.head()
f1 f2 f3
1900-01-01 0.433388 0.530670 0.603563
1900-01-02 0.420193 0.870925 0.008032
1900-01-03 0.535433 0.941497 0.407027
1900-01-04 0.754523 0.523739 0.320910
1900-01-05 0.091197 0.582181 0.834773
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.