加入两个数据帧(特殊索引)

时间:2016-11-19 00:01:48

标签: python-2.7 pandas concat

为了缩短冗长而令人困惑的故事,我有两个数据框,TFSTICK

TFS
                          openbid  highbid   lowbid  closebid  openask  highask   lowask  closeask
     DT                                                                                           
1T   2016-01-05 00:00:00  1.08241  1.08241  1.08216   1.08216  1.08242  1.08245  1.08218   1.08218
     2016-01-05 00:01:00  1.08217  1.08217  1.08179   1.08180  1.08222  1.08222  1.08185   1.08188
     2016-01-05 00:02:00  1.08183  1.08190  1.08179   1.08187  1.08188  1.08195  1.08184   1.08192
     2016-01-05 00:03:00  1.08189  1.08196  1.08183   1.08191  1.08194  1.08198  1.08191   1.08198
     2016-01-05 00:04:00  1.08193  1.08194  1.08187   1.08190  1.08198  1.08198  1.08191   1.08194
...                           ...      ...      ...       ...      ...      ...      ...       ...
240T 2016-01-05 04:00:00  1.08194  1.08366  1.08040   1.08085  1.08200  1.08371  1.08044   1.08087
     2016-01-05 08:00:00  1.08084  1.08183  1.07519   1.07557  1.08090  1.08188  1.07524   1.07563
     2016-01-05 12:00:00  1.07559  1.07648  1.07105   1.07214  1.07564  1.07652  1.07110   1.07218
     2016-01-05 16:00:00  1.07216  1.07485  1.07196   1.07431  1.07218  1.07489  1.07199   1.07435
     2016-01-05 20:00:00  1.07435  1.07583  1.07418   1.07502  1.07438  1.07588  1.07424   1.07507

[1518 rows x 8 columns]


TICK
           Bid      Ask             Time    Date_Day
0      1.08241  1.08242  00:00:00.593000  2016-01-05
1      1.08237  1.08244  00:00:00.632000  2016-01-05
2      1.08238  1.08244  00:00:00.942000  2016-01-05
3      1.08237  1.08244  00:00:01.309000  2016-01-05
4      1.08235  1.08244  00:00:01.515000  2016-01-05
...        ...      ...              ...         ...
96232  1.07496  1.07502  23:59:10.659000  2016-01-05
96233  1.07498  1.07502  23:59:12.414000  2016-01-05
96234  1.07499  1.07502  23:59:12.505000  2016-01-05
96235  1.07501  1.07507  23:59:12.621000  2016-01-05
96236  1.07502  1.07507  23:59:13.088000  2016-01-05

[96237 rows x 4 columns]

使用TFS我可以切入并使用TFS.ix['1T']获取任何特定的时间范围 - 所以我留下了:

                          openbid  highbid   lowbid  closebid  openask  highask   lowask  closeask
     DT                                                                                           
1T   2016-01-05 00:00:00  1.08241  1.08241  1.08216   1.08216  1.08242  1.08245  1.08218   1.08218
     2016-01-05 00:01:00  1.08217  1.08217  1.08179   1.08180  1.08222  1.08222  1.08185   1.08188
     2016-01-05 00:02:00  1.08183  1.08190  1.08179   1.08187  1.08188  1.08195  1.08184   1.08192
     2016-01-05 00:03:00  1.08189  1.08196  1.08183   1.08191  1.08194  1.08198  1.08191   1.08198
     2016-01-05 00:04:00  1.08193  1.08194  1.08187   1.08190  1.08198  1.08198  1.08191   1.08194

我的问题是,我可以加入TICK加入TFS,就像我加入1T240T一样吗?进入类似的东西:

                          openbid  highbid   lowbid  closebid  openask  highask   lowask  closeask
     DT                                                                                           
1T   2016-01-05 00:00:00  1.08241  1.08241  1.08216   1.08216  1.08242  1.08245  1.08218   1.08218
     2016-01-05 00:01:00  1.08217  1.08217  1.08179   1.08180  1.08222  1.08222  1.08185   1.08188
     2016-01-05 00:02:00  1.08183  1.08190  1.08179   1.08187  1.08188  1.08195  1.08184   1.08192
     2016-01-05 00:03:00  1.08189  1.08196  1.08183   1.08191  1.08194  1.08198  1.08191   1.08198
     2016-01-05 00:04:00  1.08193  1.08194  1.08187   1.08190  1.08198  1.08198  1.08191   1.08194
...                           ...      ...      ...       ...      ...      ...      ...       ...
240T 2016-01-05 04:00:00  1.08194  1.08366  1.08040   1.08085  1.08200  1.08371  1.08044   1.08087
     2016-01-05 08:00:00  1.08084  1.08183  1.07519   1.07557  1.08090  1.08188  1.07524   1.07563
     2016-01-05 12:00:00  1.07559  1.07648  1.07105   1.07214  1.07564  1.07652  1.07110   1.07218
     2016-01-05 16:00:00  1.07216  1.07485  1.07196   1.07431  1.07218  1.07489  1.07199   1.07435
     2016-01-05 20:00:00  1.07435  1.07583  1.07418   1.07502  1.07438  1.07588  1.07424   1.07507
TICK          Bid      Ask             Time    Date_Day
       0      1.08241  1.08242  00:00:00.593000  2016-01-05
       1      1.08237  1.08244  00:00:00.632000  2016-01-05
       2      1.08238  1.08244  00:00:00.942000  2016-01-05
       3      1.08237  1.08244  00:00:01.309000  2016-01-05
       4      1.08235  1.08244  00:00:01.515000  2016-01-05

我想我要问的是,是否有一种粗暴的方式将这两者混为一谈,以便我可以使用一个函数返回该批次,然后使用NEW_DF.ix['TICKS']来获取TICK df。

感谢。

0 个答案:

没有答案