Black Lives Matter. Please consider donating to Black Girls Code today.

Time conversion in candlestick plot


I’ve got some candlestick data in a numpy array, however, the time column is in Unix time.

candles = np.array(data)
x_data = candles[:,0]
open_data = candles[:,3]
high_data = candles[:,2]
low_data = candles[:,1]
close_data = candles[:,4]

trace = go.Candlestick(x=x_data,
data = [trace]
py.iplot(data, filename=‘simple_candlestick’)

now when i try to convert that time with something like “x_data = datetime.fromtimestamp(int(candles[:,0])).strftime(’%Y-%m-%d %H:%M:%S’)”
i get a “TypeError: only size-1 arrays can be converted to Python scalars” which makes sense since im feeding the whole array into the time conversion function and not just one value.

any idea how i can achieve the time conversion without having to split the time column from the full array?


Hi @sungod3k, could you add a self-contained example that produces the error you’re seeing? It’ll be much easier for folks to try to help you if they have a starting point.