average

Getting the average of a certain hour on weekdays over several years in a pandas dataframe

只愿长相守 提交于 2019-11-26 20:15:23
问题 I have an hourly dataframe in the following format over several years: Date/Time Value 01.03.2010 00:00:00 60 01.03.2010 01:00:00 50 01.03.2010 02:00:00 52 01.03.2010 03:00:00 49 . . . 31.12.2013 23:00:00 77 I would like to average the data so I can get the average of hour 0, hour 1... hour 23 of each of the years. So the output should look somehow like this: Year Hour Avg 2010 00 63 2010 01 55 2010 02 50 . . . 2013 22 71 2013 23 80 Does anyone know how to obtain this in pandas? 回答1: Note:

Avg of a Sum in one query

时光毁灭记忆、已成空白 提交于 2019-11-26 20:12:20
问题 I would like to know if I can get the average of a sum in one single SQL SERVER request, Have tried to do it with the following request but it doesn't work: SELECT t.client, AVG(SUM(t.asset)) AS Expr1 FROM TABLE t GROUP BY t.client 回答1: I think your question needs a bit of explanation. If you want to take the sums grouped by t.client you can use: SELECT t.client, SUM(t.asset) FROM the-table t GROUP BY t.client Then, if you want to take the average of this sume, just make: SELECT AVG(asset

calculate exponential moving average in python

一笑奈何 提交于 2019-11-26 19:13:03
问题 I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this? I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. Maybe I'm not looking in the right place. So, given the following code, how could I calculate the moving weighted average of IQ points for calendar dates? from datetime import date days = [date

np.mean() vs np.average() in Python NumPy?

喜你入骨 提交于 2019-11-26 18:54:56
问题 I notice that In [30]: np.mean([1, 2, 3]) Out[30]: 2.0 In [31]: np.average([1, 2, 3]) Out[31]: 2.0 However, there should be some differences, since after all they are two different functions. What are the differences between them? 回答1: np.average takes an optional weight parameter. If it is not supplied they are equivalent. Take a look at the source code: Mean, Average np.mean: try: mean = a.mean except AttributeError: return _wrapit(a, 'mean', axis, dtype, out) return mean(axis, dtype, out)

Exponential Moving Average Sampled at Varying Times

邮差的信 提交于 2019-11-26 17:57:44
问题 I have a continuous value for which I'd like to calculate an exponential moving average. Normally I'd just use the standard formula for this: S n = αY + (1-α)S n-1 where S n is the new average, α is the alpha, Y is the sample, and S n-1 is the previous average. Unfortunately, due to various issues I don't have a consistent sample time. I may know I can sample at the most, say, once per millisecond, but due to factors out of my control, I may not be able to take a sample for several

Django ORM how to Round an Avg result

半城伤御伤魂 提交于 2019-11-26 17:01:11
问题 I have a model in which I use Django ORM to extract Avg of values from the table. I want to Round that Avg value, how do I do this? See below I am extracting Avg price from Prices model grouped by date in format YYYY-MM, I want to automatically extract the average values rounded to the closest number. rs = Prices.objects.all.extra(select={ 'for_date': 'CONCAT(CONCAT(extract( YEAR from for_date ), "-"), LPAD(extract(MONTH from for_date), 2, "00"))' }).values('for_date').annotate(price=Avg(

How to find average from array in php?

a 夏天 提交于 2019-11-26 16:48:43
问题 Example: $a[] = '56'; $a[] = '66'; $a[] = ''; $a[] = '58'; $a[] = '85'; $a[] = ''; $a[] = ''; $a[] = '76'; $a[] = ''; $a[] = '57'; Actually how to find average value from this array excluding empty. please help to resolve this problem. 回答1: first you need to remove empty values, otherwise average will be not accurate. so $a = array_filter($a); $average = array_sum($a)/count($a); echo $average; DEMO More concise and recommended way $a = array_filter($a); if(count($a)) { echo $average = array

Calculating arithmetic mean (one type of average) in Python

一笑奈何 提交于 2019-11-26 12:42:20
Is there a built-in or standard library method in Python to calculate the arithmetic mean (one type of average) of a list of numbers? NPE I am not aware of anything in the standard library. However, you could use something like: def mean(numbers): return float(sum(numbers)) / max(len(numbers), 1) >>> mean([1,2,3,4]) 2.5 >>> mean([]) 0.0 In numpy, there's numpy.mean() . NumPy has a numpy.mean which is an arithmetic mean. Usage is as simple as this: >>> import numpy >>> a = [1, 2, 4] >>> numpy.mean(a) 2.3333333333333335 kirbyfan64sos Use statistics.mean : import statistics print(statistics.mean(

Calculating average of an array list?

隐身守侯 提交于 2019-11-26 11:24:18
问题 I\'m trying to use the below code to calculate the average of a set of values that a user enters and display it in a jTextArea but it does not work properly. Say, a user enters 7, 4, and 5, the program displays 1 as the average when it should display 5.3 ArrayList <Integer> marks = new ArrayList(); Collections.addAll(marks, (Integer.parseInt(markInput.getText()))); private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) { analyzeTextArea.setText(\"Class average:\" +

Finding moving average from data points in Python

China☆狼群 提交于 2019-11-26 07:23:16
问题 I am playing in Python a bit again, and I found a neat book with examples. One of the examples is to plot some data. I have a .txt file with two columns and I have the data. I plotted the data just fine, but in the exercise it says: Modify your program further to calculate and plot the running average of the data, defined by: $Y_k=\\frac{1}{2r}\\sum_{m=-r}^r y_{k+m}$ where r=5 in this case (and the y_k is the second column in the data file). Have the program plot both the original data and