I have struggle understanding the following anomaly, though I am sure it is ridiculously simple.
I have a list raw_ticker, with the following values:
raw_ticker = ['t1INCH:USD', 3.5881, 17907.680602819994, 3.5945, 10610.799208380002, -0.0172, -0.0048, 3.5982, 300068.50303883, 3.9639, 2.7685]
I want to convert it to a numpy array ticker, and specify the data types:
ticker = np.array(raw_ticker,
dtype=[
('symbol', str),
('bid', float),
('bid_size', float),
('ask', float),
('ask_size', float),
('day_chg', float),
('day_chg_p', float),
('last', float),
('vol', float),
('high', float),
('low', float)])
I get the following error :
could not convert string to float: 't1INCH:USD'
which I don't get as I explicitly specified that this field is a string, not a float.
dtype, a compound one. OP - the data for a structured array needs to a tuple or list of tuples.ticker = np.array(raw_ticker[1:]), and then load the floats. You could also load multiple tickers into e.g. a dict[str, List[relevant datatype]] and use something like Pandas DataFrames or PyArrow Tables to organize your data on columnar basis.a = np.array(['1', 2])becomes['1', '2']