Posted at

objectのlistの和を取る

holoviewsのobjectをlistに収めていきまとめて和ととるとsumを使ったらうまく行かなかったのでメモ

import quandl

import holoviews as hv
hv.extension('bokeh')

curve_lst = []
df = quandl.get("TSE/1321", start='2018-01-01', end='2018-12-31')
curve_lst.append(hv.Curve(df, 'Date', 'Low'))
curve_lst.append(hv.Curve(df, 'Date', 'Low'))
curve_lst.append(hv.Curve(df, 'Date', 'Low'))

sum(curve_lst)

これはerrorになる

TypeError: unsupported operand type(s) for +: 'int' and 'Curve'

import quandl

import holoviews as hv
hv.extension('bokeh')

curve_lst = []
df = quandl.get("TSE/1321", start='2018-01-01', end='2018-12-31')
curve_lst.append(hv.Curve(df, 'Date', 'Low'))
curve_lst.append(hv.Curve(df, 'Date', 'Low'))
curve_lst.append(hv.Curve(df, 'Date', 'Low'))

import functools
functools.reduce(lambda x, y: x+y, curve_lst)

これで動く

image.png