我有一组打包到文件中的二进制记录,我正在使用Data.ByteString.Lazy和Data.Binary.Get读取它们.使用我当前的实现,8Mb文件需要6秒才能解析.
import qualified Data.ByteString.Lazy as BL
import Data.Binary.Get
data Trade = Trade { timestamp :: Int, price :: Int , qty :: Int } deriving (Show)
getTrades = do
empty <- isEmpty
if empty
then return []
else do
timestamp <- getWord32le
price <- getWord32le
qty <- getWord16le
rest <- getTrades
let trade = Trade (fromIntegral timestamp) (fromIntegral price) (fromIntegral qty)
return (trade : rest)
main :: IO()
main = do
input <- BL.readFile "trades.bin"
let trades = runGet getTrades …Run Code Online (Sandbox Code Playgroud) 我想在重新采样pandas DataFrame时创建多个列,就像内置的ohlc方法一样.
def mhl(data):
return pandas.Series([np.mean(data),np.max(data),np.min(data)],index = ['mean','high','low'])
ts.resample('30Min',how=mhl)
Run Code Online (Sandbox Code Playgroud)
死了
Exception: Must produce aggregated value
Run Code Online (Sandbox Code Playgroud)
有什么建议?谢谢!
我想在不添加新的日子的情况下对一些日内数据进行下采样
df.resample('30Min')
Run Code Online (Sandbox Code Playgroud)
会增加不受欢迎的周末等.有没有办法解决?
我想在seaborn图表上更改水平网格线的间距,我尝试设置样式没有运气:
seaborn.set_style("whitegrid", {
"ytick.major.size": 0.1,
"ytick.minor.size": 0.05,
'grid.linestyle': '--'
})
bar(range(len(data)),data,alpha=0.5)
plot(avg_line)
Run Code Online (Sandbox Code Playgroud)
网格线自动设置我试图覆盖刻度尺寸
有什么建议?谢谢!
如何改进以下滚动总和实施?
type Buffer = State BufferState (Maybe Double)
type BufferState = ( [Double] , Int, Int )
-- circular buffer
buff :: Double -> Buffer
buff newVal = do
( list, ptr, len) <- get
-- if the list is not full yet just accumulate the new value
if length list < len
then do
put ( newVal : list , ptr, len)
return Nothing
else do
let nptr = (ptr - 1) `mod` len
(as,(v:bs)) = splitAt ptr list …Run Code Online (Sandbox Code Playgroud) haskell ×2
pandas ×2
python ×2
time-series ×2
binaryfiles ×1
graph ×1
matplotlib ×1
performance ×1
plotly-dash ×1
seaborn ×1
state-monad ×1