[英]How to allocation a bunch of 2-D array into each grid as a time series Pandas.DataFrame?
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 . 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. 我想从二维数组中提取每个网格的数据,然后按照时间序列将每个网格保存到一个独立的DataFrame中。
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: 看起来,只创建一个数据帧,而f1,f2,f3是不同的列可能会更好:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.