我有这样的多个时间序列:
DATE
2015-10-10 01:00:00 955.0
2015-10-11 01:00:00 702.0
2015-10-12 01:00:00 597.0
2015-10-13 01:00:00 516.0
2015-10-14 01:00:00 554.0
DATE
2015-10-10 02:00:00 972.0
2015-10-11 02:00:00 646.0
2015-10-12 02:00:00 529.0
2015-10-13 02:00:00 554.0
2015-10-14 02:00:00 540.2
DATE
2015-10-10 03:00:00 964.0
2015-10-11 03:00:00 707.0
2015-10-12 03:00:00 557.0
2015-10-13 03:00:00 515.0
2015-10-14 03:00:00 437.2
我想要做的是从这些时间序列中创建一个ordred和唯一的Time Serie来获得这个结果:
DATE
2015-10-10 00:00:00 622.0
2015-10-10 01:00:00 955.0
2015-10-10 02:00:00 972.0
2015-10-10 03:00:00 964.0
2015-10-10 04:00:00 914.0
...
2015-10-11 00:00:00 923.0
2015-10-11 01:00:00 955.0
2015-10-11 02:00:00 646.0
答案 0 :(得分:1)
您可以使用concat
逐行连接并在结果上调用sort_index()
以获得所需的结果:
pd.concat(list_of_series).sort_index()
答案 1 :(得分:-1)
您也可以尝试使用RedBlackPy。该库旨在有效处理动态数据(例如时间序列)。
import redblackpy as rb
from datetime import datetime
series = rb.Series(dtype='float32', interpolate='floor')
# When you insert items, it is automatically sorted.
# Because rb.Series uses red-black trees as a core structure,
# and you can add items and doesn't think about order.
series.insert(datetime(2015,10,10), 955).
# if you have a list of rb.Series objects, than to construct sorted
# union of theirs keys in efficient way you can use rb.SeriesIterator
# which do not use additional memory to concat because it is a generator.
iterator = rb.SeriesIterator(list_of_rb_Series)
for key in iterator('forward'): # or 'reverse' order
key # key from sorted union of the keys, it is constructed inplace