简体   繁体   English

如何将具有日分辨率的Numpy时间序列库存数据转换为月或周分辨率

[英]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.

相关问题 Pandas 每周营业日股票价格数据 - Pandas Week of the Month Business Day Stock Price Data 将月中的某一天转换为周 - Convert day of the month to week 如何用 python 中前一周(天)的同一天和同一时间的值来估算时间序列数据中的缺失值 - How to impute missing value in time series data with the value of the same day and time from the previous week(day) in python 时间序列数据:每天的bin数据,然后按星期几绘制 - Time series data: bin data to each day, then plot by day of week 从时间序列数据生成每月的第一个和最后一个工作日 - Generate first and last working day of month from time series data 在月底和一天结束时重新采样时间序列数据 - Resample a time-series data at the end of the month and at the end of the day 用前一周(天)或前一天的数据填充 pandas 时间序列中的缺失数据? - fill missing data in pandas time series with data from the previous week(day) or day? 如何从星期几获取月几号? - How to obtain day of the month from day of the week? 如何提供星期几和星期几 - How to calculate day of the week provided the day and month 使用当月的第一个交易日将每日大熊猫股票数据转换为月度数据 - Convert daily pandas stock data to monthly data using first trade day of the month
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM