简体   繁体   English

如何将一堆二维数组作为时间序列Pandas.DataFrame分配到每个网格中?

[英]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.

相关问题 python中时间序列的二维网格插值 - 2-D grid interpolation for time series in python 以 numpy.array()、pandas.DataFrame() 或 xarray.DataSet() 的形式展开时间序列以包含作为 NaN 的缺失记录 - Expand a time series in the form of numpy.array(), pandas.DataFrame(), or xarray.DataSet() to contain the missing records as NaN 使用默认值将pandas.DataFrame列分配给Series - Assign pandas.DataFrame column To Series with Default Pandas.DataFrame:如何按每行中的最大值对行进行排序 - Pandas.DataFrame: How to sort rows by the largest value in each row 如何对pandas.DataFrame中的每一行进行明确排名 - How to rank distinctly for each row in pandas.DataFrame 如何使 Pandas DataFrame (Python) 以二维 (2-D) 矩阵格式显示每个单元格 - how to make Pandas DataFrame (Python) to display each cell in a two dimensional (2-D) matrix format 如何在 pandas.DataFrame 上将“.”替换为“,” - How To Replace " . " With " , " on a pandas.DataFrame 如何在 pandas.DataFrame 中将“对象/字符串”类型转换为“时间”类型? - How to convert from 'object/string' to 'time' type in pandas.DataFrame? 使用二维numpy数组有效填充熊猫数据帧 - Populating pandas dataframe efficiently using a 2-D numpy array pandas.DataFrame - 获取每一行的 UID? - pandas.DataFrame - get the UID of each row?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM