python 结构数组_python numpy数组的结构

I would like to ask a completely new question regarding this code.

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)

As per Dan's help, quotes returns:

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.

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]])

and:

>>> 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]])

>>>

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 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')

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值