[英]How to convert numpy time series stock data with day resolution to month or week resolution
I am working with a python script from Harrison Kinsley to plot stock data ( Link ) 我正在使用Harrison Kinsley的python脚本来绘制库存数据( Link )
The script was modified to accept data from a csv with very detailed time series data (day per day resolution timesteps). 修改了脚本,以接受具有非常详细的时间序列数据(每天的分辨率时间步长)的csv数据。 The csv is loaded into numpy on this line.
在此行将csv加载到numpy中。
date, closep, highp, lowp, openp, volume = np.loadtxt(out,delimiter=',', unpack=True,
converters={ 0: mdates.strpdate2num('%Y%m%d')})
Is it somehow possible to convert the data to less datapoints? 是否可以将数据转换为较少的数据点? Month by month resolution or week by week resolution?
按月分辨率还是按周分辨率?
Well, you didn't say exactly what do you want to do. 好吧,您没有确切地说出您想做什么。 Less datapoints means that you either pick any random datapoint, of perform some operation: here you got many possibilities: get the median or average for a given day/week/month, or maybe max/min values, whatever you want, really.
较少的数据点意味着您可以选择任何随机的数据点来执行一些操作:在这里您有很多可能性:可以获取给定的日/周/月的中位数或平均值,或者实际上可以是最大值/最小值。 The code:
编码:
import numpy as np
share_prices = np.array([100,102,104,106,104, 109, 110])
median_price = np.median(share_prices)
104.0
average_price = np.average(share_prices)
105.0
min_price = np.min(share_prices)
100
max_price = np.max(share_prices)
110
All of that would be much easier and more fun with awesome Pandas module written exactly for that purpose. 正是为此目的而编写的出色的Pandas模块,所有这些都将变得更加容易和有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.