moving-average

Python Pandas: Calculate moving average within group

主宰稳场 提交于 2020-03-18 04:36:06
问题 I have a dataframe containing time series for 100 objects: object period value 1 1 24 1 2 67 ... 1 1000 56 2 1 59 2 2 46 ... 2 1000 64 3 1 54 ... 100 1 451 100 2 153 ... 100 1000 21 I want to calculate moving average with window 10 for the value column. I guess I have to do something like df.groupby('object').apply(lambda ~calculate MA~) and then merge this Series to the original dataframe by object? Can't figure out exact commands 回答1: You can use rolling with transform : df['moving'] = df

How to use Exponential Moving Average in Tensorflow

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-22 09:50:11
问题 The problem Tensorflow includes the function tf.train.ExponentialMovingAverage which allows us to apply a moving average to the parameters, which I've found to be great to stabilize the testing of the model. With that said, I've found it somewhat irritatingly hard to apply this to general models. My so far most successful approach (shown below) has been to write a function decorator and then put my whole NN inside a function. This does however have several downsides. For one, it duplicates

Understanding NumPy's Convolve

心已入冬 提交于 2020-01-19 18:20:53
问题 When calculating a simple moving average, numpy.convolve appears to do the job. Question: How is the calculation done when you use np.convolve(values, weights, 'valid') ? When the docs mentioned convolution product is only given for points where the signals overlap completely , what are the 2 signals referring to? If any explanations can include examples and illustrations, it will be extremely useful. window = 10 weights = np.repeat(1.0, window)/window smas = np.convolve(values, weights,

SQLITE moving average

。_饼干妹妹 提交于 2020-01-17 07:36:48
问题 Trying to get the moving average on a per X months basis using SQLite. Problem is i cannot seem to figure or find anything remotely useful on how to aggregate with a X month(s) lookback period and thus create a moving average. Table CREATE TABLE "nav" ( `id` TEXT, `nav` NUMERIC, `date` TEXT ); Sample data id nav date 1380 15.3 2005-01-09 1380 15.4 2005-01-16 1380 15.5 2005-01-23 1380 15.55 2005-01-30 1380 15.66 2005-02-06 1380 15.45 2005-02-13 1380 15.26 2005-02-20 1380 15.14 2005-02-27 1380

12 month moving average by person, date

岁酱吖の 提交于 2020-01-15 10:48:27
问题 I have a table [production] that contains the following structure: rep (char(10)) ,cyc_date (datetime) ---- already standardized to mm/01/yyyy ,amt (decimal) I have data for each rep from 1/1/2011 to 8/1/2013. What I want to be able to do is create a 12 month moving average beginning 1/1/2012 for each rep, as follows: rep cyc_dt 12moAvg ------------------------- A 1/1/2012 10000.01 A 2/1/2012 13510.05 . ........ ........ A 8/1/2013 22101.32 B 1/1/2012 98328.22 B ........ ........ where each

Spark: structure of intraday data of 100 stocks to efficiently calculate moving averages etc. per stock

怎甘沉沦 提交于 2020-01-14 10:24:27
问题 I'm new to Spark and need to do an assignment in which I will predict the stock price direction using Random Forests. To do this I need to calculate certain features like Moving Average. I already read in my data (100 csv files with 6 columns: time, open, close, high, low, volume) using wholeTextFiles. So now I have an RDD of file names and content. What is the most efficient way to transform this RDD in order to be able to calculate the moving average of the close column? Should I make an

How to perform packet pair probing by sending multiple packets rather than just one pair ? (method for taking average)

夙愿已清 提交于 2020-01-13 06:39:31
问题 Generally in a packet pair estimation, you are supposed to send multiple bursts of packet pairs and take an average of the bandwidths. Say, you send 4 packets, calculate the time difference between the first two packets(1&2), time difference between the next two packets(3&4). Calculate bandwidth for each of these two and then take average. Or Calculate the time difference between (1&2), time difference between (3&2), time difference between (4&3)... and then take an average out of these

How to perform packet pair probing by sending multiple packets rather than just one pair ? (method for taking average)

痴心易碎 提交于 2020-01-13 06:39:19
问题 Generally in a packet pair estimation, you are supposed to send multiple bursts of packet pairs and take an average of the bandwidths. Say, you send 4 packets, calculate the time difference between the first two packets(1&2), time difference between the next two packets(3&4). Calculate bandwidth for each of these two and then take average. Or Calculate the time difference between (1&2), time difference between (3&2), time difference between (4&3)... and then take an average out of these

How do I calculate a rolling mean with custom weights in pandas?

落花浮王杯 提交于 2020-01-11 11:50:28
问题 The Pandas documentation http://pandas.pydata.org/pandas-docs/stable/computation.html has an example of how to calculate moving averages: ser = pd.Series(np.random.randn(10), index=pd.date_range('1/1/2000', periods=10)) pd.rolling_window(ser, 5, 'boxcar') The second line calculates a rolling average with a window of 5 and equal weights on each of the five observations. The docs refer tantalizingly to the possibility of using custom weights ("When passing a win_type instead of explicitly

How do I calculate a rolling mean with custom weights in pandas?

浪子不回头ぞ 提交于 2020-01-11 11:49:17
问题 The Pandas documentation http://pandas.pydata.org/pandas-docs/stable/computation.html has an example of how to calculate moving averages: ser = pd.Series(np.random.randn(10), index=pd.date_range('1/1/2000', periods=10)) pd.rolling_window(ser, 5, 'boxcar') The second line calculates a rolling average with a window of 5 and equal weights on each of the five observations. The docs refer tantalizingly to the possibility of using custom weights ("When passing a win_type instead of explicitly