![](/img/trans.png)
[英]How to create multiple Pandas time series from a data frame using python?
[英]Create Pandas Time Serie from multiple Time Series with Python
我有這樣的多個時間序列:
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
您可以使用concat
逐行連接並在結果上調用sort_index()
以獲得所需的結果:
pd.concat(list_of_series).sort_index()
您也可以嘗試使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.