Questions tagged [average]

In mathematics, an average is a measure of the "middle" or "typical" value of a data set. Different types of averages include the arithmetic mean, the median, and the mode.

In the most common case, the data set is a list of numbers. The average of a list of numbers is a single number intended to typify the numbers in the list. If all the numbers in the list are the same, then this number should be used. If the numbers are not the same, the average is calculated by combining the numbers from the list in a specific way and computing a single number as being the average of the list.

Many different descriptive statistics can be chosen as a measure of the central tendency of the data items. These include the arithmetic mean, the median, and the mode. Other statistics, such as the standard deviation and the range, are called measures of spread and describe how spread out the data is.

See also: , ,

5780 questions
38
votes
4 answers

SQL AVG returning an int

In one of my queries it appears that the AVG function is returning an int. select ..., AVG(e.employee_level)avg_level How do I get it to return floating point values? I tried casting it but all my rows for avg_level were still integers.
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
38
votes
1 answer

AVG in Sql - Float number problem

SELECT AVG(variable) AS Expr1, SUM(variable) AS Expr2 FROM ...... result for AVG is 2, but it is not true, it must be 2.95. What is the problem, any idea?
NetSide
  • 3,849
  • 8
  • 30
  • 41
33
votes
16 answers

calculate exponential moving average in python

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…
Jim
  • 11,229
  • 20
  • 79
  • 114
32
votes
5 answers

Weighted averaging a list

Thanks for your responses. Yes, I was looking for the weighted average. rate = [14.424, 14.421, 14.417, 14.413, 14.41] amount = [3058.0, 8826.0, 56705.0, 30657.0, 12984.0] I want the weighted average of the top list based on each item of the…
Rontron
  • 3,963
  • 7
  • 26
  • 44
32
votes
2 answers

Moving average in postgresql

I have the following table in my Postgresql 9.1 database: select * from ro; date | shop_id | amount -----------+----------+-------- 2013-02-07 | 1001 | 3 2013-01-31 | 1001 | 2 2013-01-24 | 1001 | 1 2013-01-17 | …
Glicious
  • 421
  • 1
  • 5
  • 13
31
votes
4 answers

Avg of a Sum in one query

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
Roch
  • 21,741
  • 29
  • 77
  • 120
29
votes
2 answers

Fastest way to take the average of two signed integers in x86 assembly?

Suppose we have two register-length2 signed1 integers, say a and b. We want to compute the value (a + b) / 2, either rounded up, down, towards zero, or away from zero, whichever way is easier (i.e. we do not care about the rounding direction). The…
Bernard
  • 5,209
  • 1
  • 34
  • 64
28
votes
4 answers

Average timedelta in list

I want to calculate the avarage timedelta between dates in a list. Although the following works well, I'm wondering if there's a smarter way? delta = lambda last, next: (next - last).seconds + (next - last).days * 86400 total =…
shinn
  • 291
  • 1
  • 3
  • 4
28
votes
2 answers

Average across Columns in R, excluding NAs

I can't imagine I'm the first person with this question, but I haven't found a solution yet (here or elsewhere). I have a few columns, which I want to average in R. The only minimally tricky aspect is that some columns contain NAs. For…
mfk534
  • 719
  • 1
  • 9
  • 21
26
votes
2 answers

Select average from MySQL table with LIMIT

I am trying to get the average of the lowest 5 priced items, grouped by the username attached to them. However, the below query gives the average price for each user (which of course is the price), but I just want one answer returned. SELECT…
James Simpson
  • 13,488
  • 26
  • 83
  • 108
24
votes
8 answers

Is there any pythonic way to find average of specific tuple elements in array?

I want to write this code as pythonic. My real array much bigger than this example. ( 5+10+20+3+2 ) / 5 print(np.mean(array,key=lambda x:x[1])) TypeError: mean() got an unexpected keyword argument 'key' array = [('a', 5) , ('b', 10), ('c', 20),…
Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37
24
votes
3 answers

Average extension method in Linq for default value

Anyone know how I can set a default value for an average? I have a line like this... dbPlugins = (from p in dbPlugins select new { Plugin = p, AvgScore = p.DbVersions.Average(x => x.DbRatings.Average(y => y.Score)) }) …
Rush Frisby
  • 11,388
  • 19
  • 63
  • 83
23
votes
1 answer

Pyspark:How to calculate avg and count in a single groupBy?

I would like to calculate avg and count in a single group by statement in Pyspark. How can I do that? df = spark.createDataFrame([(1, 'John', 1.79, 28,'M', 'Doctor'), (2, 'Steve', 1.78, 45,'M', None), …
melik
  • 1,268
  • 3
  • 21
  • 42
23
votes
4 answers

How can I divide single values of a dataframe by monthly averages?

I have the following 15 minute data as a dataframe for 3 years. With the first two columns being the index. 2014-01-01 00:15:00 1269.6 2014-01-01 00:30:00 1161.6 2014-01-01 00:45:00 1466.4 2014-01-01 01:00:00 1365.6 …
Markus W
  • 1,451
  • 5
  • 19
  • 32
22
votes
4 answers

Mysql AVG to ignore zero

I need to perform an avg on a column, but I know that most of the values in that column will be zero. Out of all possible rows, only two will probably have positive values. How can I tell mySQL to ignore the zeros and only average the actual values?
Oranges13
  • 1,084
  • 1
  • 10
  • 33