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
14
votes
2 answers

Pandas dataframe: Group by two columns and then average over another column

Assuming that I have a dataframe with the following values: df: col1 col2 value 1 2 3 1 2 1 2 3 1 I want to first groupby my dataframe based on the first two columns (col1 and col2) and then average over…
ahajib
  • 12,838
  • 29
  • 79
  • 120
13
votes
1 answer

"circular" mean in R

Given a dataset of months, how do I calculate the "average" month, taking into account that months are circular? months = c(1,1,1,2,3,5,7,9,11,12,12,12) mean(months) ## [1] 6.333333 In this dummy example, the mean should be in January or December. …
generic_user
  • 3,430
  • 3
  • 32
  • 56
13
votes
10 answers

Random number with fixed average

I want to generate 100 random numbers between 1 and 10. But the average of those 100 random numbers should be 7. How can I do that? I am doing as follows: //generating random number Random random = new Random(); int value = random.Next(1,10); And…
M.S
  • 288
  • 4
  • 12
13
votes
8 answers

What's the quickest way to get the mean of a set of numbers from the command line?

Using any tools which you would expect to find on a nix system (in fact, if you want, msdos is also fine too), what is the easiest/fastest way to calculate the mean of a set of numbers, assuming you have them one per line in a stream or file?
Anthony
  • 1,306
  • 4
  • 13
  • 23
13
votes
2 answers

getting the average, p95 and p99 of a stream of data

I have incoming data and I want to compute the average, 95th and 99th percentile of that data - I am most interested in the last 1000 values. At any time, I'd like to query this object to get any of the three values (this can occur at any time, not…
jamesatha
  • 7,280
  • 14
  • 37
  • 54
12
votes
6 answers

How to convert a list of strings into a numeric numpy array?

I want to be able to calculate the mean, min and max of A: import numpy as np A = ['33.33', '33.33', '33.33', '33.37'] NA = np.asarray(A) AVG = np.mean(NA, axis=0) print AVG This does not work, unless converted to: A = [33.33, 33.33,…
Cristian J Estrada
  • 357
  • 2
  • 3
  • 14
12
votes
5 answers

Average of two timestamps in python

I have two timestamps (pandas.tslib.Timestamp) ts1 and ts2 and I want to calculate the average of them. (ts1+ts2)/2 However, I am getting this error: TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp' Thank you for any help.
Karel Macek
  • 1,119
  • 2
  • 11
  • 24
12
votes
2 answers

Find average date from collection of dates (Ruby)

I have a table of guesses, within each guess is just a date. I was wondering how I would go about turning two or more dates into an average.
<% foo = Date.today %> <% bar = Date.today + 10 %> <%= (foo + bar) / 2 %> Something like…
Karl Entwistle
  • 933
  • 2
  • 13
  • 25
12
votes
1 answer

How to find average intensity of OpenCV contour in realtime

I have a image with about 50 to 100 small contours. I wish to find the average intensity[1] of each of these contours in real-time[2]. Some of the ways I could think of was Draw contour with FILLED option for each contour; use each image as a mask…
Ashok
  • 1,079
  • 3
  • 10
  • 17
12
votes
7 answers

Calculate cumulative average (mean)

I would like to know how to calculate the cumulative average for some numbers. I will give a simple example to describe what I am looking for. I have the following numbers vec <- c(1, 2, 3, 4, 5) If I do the average of these numbers I will get 3…
MR BIG
  • 163
  • 1
  • 1
  • 6
11
votes
4 answers

How can I get xtabs to calculate means instead of sums in R?

I have a data frame where each line represents an individual. That data frame has two variables: age and year. I want to make a table of average ages per year. How can I do it? The best I could come up with was xtabs(age ~ year, dataframe), but this…
Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
11
votes
5 answers

Extremely large weighted average

I am using 64 bit matlab with 32g of RAM (just so you know). I have a file (vector) of 1.3 million numbers (integers). I want to make another vector of the same length, where each point is a weighted average of the entire first vector, weighted by…
Micah Manary
  • 217
  • 2
  • 11
11
votes
2 answers

Add an average line to an existing plot

I want to add an average line to the existing plot. library(ggplot2) A <- c(1:10) B <- c(1,1,2,2,3,3,4,4,5,5) donnees <- data.frame(A,B)…
Flo
  • 151
  • 1
  • 1
  • 6
11
votes
4 answers

How to calculate average in Django?

I have Category and Product models below: class Category(models.Model): name = models.CharField(max_length=20) class Product(models.Model): category = models.ForeignKey(Category, on_delete=models.CASCADE) name =…
yaboinav
  • 121
  • 1
  • 1
  • 4
11
votes
5 answers

Average of latest N records per group

My current application calculates a point average based on all records for each user: SELECT `user_id`, AVG(`points`) AS pts FROM `players` WHERE `points` != 0 GROUP BY `user_id` The business requirement has changed and I need to calculate the…
JV-
  • 406
  • 1
  • 4
  • 11