时间序列数据集将数据拆分为大小相等的块

时间:2019-05-25 09:31:11

标签: python pandas

我有时间序列数据集,用于预测股市价格,格式为:日期为2015-2019,时间步长为t1-t300,带有浮动值。

Date         t1     t2    t3    t4  ... t300
01-01-2019   -0.34  0.40  0.50  1.2
02-01-2019   0.45   0.56  0.34  0.45
 ...

我想将每一行拆分为相等的数据块(50个时间步),并将其附加到数组。

期望数组,t1-t50表示直到t50为止的t1,t2,t3,t4的值,依此类推。

[ 
   [[t1-t50],[t50-t100],[t100-t150],[t150-t200],[t200-t250],[t250-t300] ],
   [[t1-t50],[t50-t100],[t100-t150],[t150-t200],[t200-t250],[t250-t300] ],
   ...
 ]

谢谢。

1 个答案:

答案 0 :(得分:4)

IIUC,您需要将df拆分为2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): </body> in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): ^ in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 7: parser error : Opening and ending tag mismatch: body line 3 and html in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): </html> in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): ^ in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 7: parser error : Premature end of data in tag html line 1 in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): </html> in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 2019-05-25T07:30:06+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): ^ in /ho2/xxxx/xxxxx/xxxxx/includes/src/Mage_AdminNotification_Model_Feed.php on line 173 ,使用np.split()

axis=1

添加示例:

np.split(df,df.shape[1]/50,axis=1)
#or np.split(df.values,df.shape[1]/50,axis=1)

df=pd.DataFrame(np.arange(0,30).reshape(5,6))
print(df)

基于上述df如果我想将每一行拆分为3个值:

    0   1   2   3   4   5
0   0   1   2   3   4   5
1   6   7   8   9  10  11
2  12  13  14  15  16  17
3  18  19  20  21  22  23
4  24  25  26  27  28  29

np.split(df.values,df.shape[1]/3,axis=1)