[問題] shape不同怎操作

看板Python作者 (中年魯蛇聯盟)時間2年前 (2021/10/11 12:14), 2年前編輯推噓4(402)
留言6則, 3人參與, 2年前最新討論串1/1
取得日線和4H歷史資料 2個不同shape的Series怎麼做操作 print(ohlcv_D.close.shape) #(1517,) print(ohlcv.close.shape) #(36257,) 想把他加到 entries = crossover(macdhist, 0) & (ohlcv_D.close.shift(1)>ohlcv_D.close.shift(2)) 會出現ValueError: shape mismatch: objects cannot be broadcast to a single shape ohlcv_D timestamp 2017-08-17 00:00:00+00:00 4285.08 2017-08-18 00:00:00+00:00 4108.37 2017-08-19 00:00:00+00:00 4139.98 2017-08-20 00:00:00+00:00 4086.29 2017-08-21 00:00:00+00:00 4016.00 ohlcv(4H) timestamp 2017-08-17 04:00:00+00:00 4308.83 2017-08-17 05:00:00+00:00 4315.32 2017-08-17 06:00:00+00:00 4324.35 2017-08-17 07:00:00+00:00 4349.99 2017-08-17 08:00:00+00:00 4360.69 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.37.0.83 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1633925687.A.548.html

10/11 12:47, 2年前 , 1F
應該是crossover function出來的大小跟要AND的大於結
10/11 12:47, 1F

10/11 12:47, 2年前 , 2F
果不一樣 這邊要檢查
10/11 12:47, 2F
謝謝回答 4H和1D大小本來就不一樣 要怎做處理? ※ 編輯: bxc (114.37.0.83 臺灣), 10/11/2021 12:51:37

10/11 14:05, 2年前 , 3F
index都已是time series把1D upsampling成4H
10/11 14:05, 3F

10/11 16:34, 2年前 , 4F
ohlcv_D.resample("4H").ffill()
10/11 16:34, 4F

10/11 16:45, 2年前 , 5F
看錯了QQ,我的方法不行
10/11 16:45, 5F

10/11 20:28, 2年前 , 6F
謝謝回答 答案是用reindex(index=ohlcv.index, method='ffill
10/11 20:28, 6F
文章代碼(AID): #1XOxetL8 (Python)