python numpy数组的结构 [英] structure of python numpy arrays
问题描述
我想问一个关于此代码的全新问题.
I would like to ask a completely new question regarding this code.
上面链接中的代码返回open
和close
的numpy数组:
The code in the link above returns a numpy array for open
and close
:
open = np.array([q.open for q in quotes]).astype(np.float)
close = np.array([q.close for q in quotes]).astype(np.float)
根据 Dan的帮助,quotes
返回:
在您的情况下,您使用的是asobject = True,因此获得的格式为 日期,年,月,日,d,打开,关闭,高,低,音量, Adjusted_close.
In your case you are using asobject=True so the format you get is date, year, month, day, d, open, close, high, low, volume, adjusted_close.
因此,打开和关闭必须是quotes
的元素[5]
和[6]
.
Therefore, open and close must be elements [5]
and [6]
of quotes
.
>>> open
array([[ 28.12235692, 28.32908451, 28.482779 , ..., 84.8198783 ,
84.1401 , 84.64308037],
[ 22.49848073, 22.66286426, 22.91112016, ..., 63.66703704,
64.57105722, 64.12120097]])
和:
>>> close
array([[ 28.5 , 28.53, 29.23, ..., 83.8 , 84.99, 83.82],
[ 22.91, 22.71, 23.53, ..., 63.52, 64.78, 63.92]])
>>>
我不完全理解open
和close
代表什么.
I do not understand exacty what open
and close
represent.
打开和关闭该特定股票的所有价格的每个元素是吗?
Is each element of open and close all the prices for that specific stock?
您能帮助我准确了解打开和关闭包含哪些内容吗? 它们只是每天每个符号的价格列表吗?
Can you please help me to understand exactly what do open and close contain? Are they just lists of lists of prices per symbol per day?
推荐答案
quotes
是一个包含每个交易品种的股票信息的列表:
quotes
is a list which contains stock information per symbol:
In [43]: len(quotes)
Out[43]: 61
In [44]: len(symbols)
Out[44]: 61
In [45]: symbols
Out[45]:
array(['COP', 'AXP', 'RTN', 'BA', 'AAPL', 'PEP', 'NAV', 'GSK', 'MSFT',
'KMB', 'R', 'SAP', 'GS', 'CL', 'WAG', 'WMT', 'GE', 'SNE', 'PFE',
'AMZN', 'MAR', 'NVS', 'KO', 'MMM', 'CMCSA', 'SNY', 'IBM', 'CVX',
'WFC', 'DD', 'CVS', 'TOT', 'CAT', 'CAJ', 'BAC', 'AIG', 'TWX', 'HD',
'TXN', 'KFT', 'VLO', 'NWS', 'F', 'CVC', 'TM', 'PG', 'LMT', 'K',
'HMC', 'GD', 'HPQ', 'DELL', 'MTU', 'XRX', 'YHOO', 'XOM', 'JPM',
'MCD', 'CSCO', 'NOC', 'UN'],
dtype='|S17')
例如,quotes
中的第一个元素用于'COP'符号,并包含按日期排列的值数组:
For example the first element in quotes
is for the 'COP' symbol and contains an array of values by date:
In [49]: symbols[0]
Out[49]: 'COP'
In [50]: quotes[0].open
Out[50]:
array([ 13.81001419, 14.01678947, 14.01500099, ..., 56.77238579,
56.82699428, 56.89080408])
In [51]: quotes[0].date
Out[51]:
array([2003-01-02, 2003-01-03, 2003-01-06, ..., 2007-12-27, 2007-12-28,
2007-12-31], dtype=object)
这篇关于python numpy数组的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!