Questions tagged [mean]

The arithmetic mean (or simply the mean or average when the context is clear) is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection.

The arithmetic mean, or simply the mean or when the context is clear, is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection. Besides the arithmetic mean, the geometric mean and the harmonic mean can be calculated as well.

Means apply an equal weight to every member of a collection of numbers. This feature makes means not robust to outlier members. cf.

Source: Wikipedia

3925 questions
8
votes
3 answers

How to calculate daily averages from noon to noon with pandas?

I am fairly new to python and pandas, so I apologise for any future misunderstandings. I have a pandas DataFrame with hourly values, looking something like this: 2014-04-01 09:00:00 52.9 41.1 36.3 2014-04-01 10:00:00 56.4 41.6 …
NeedHelp
  • 83
  • 4
8
votes
5 answers

computing the mean for python datetime

I have a datetime attribute: d = { 'DOB': pd.Series([ datetime.datetime(2014, 7, 9), datetime.datetime(2014, 7, 15), np.datetime64('NaT') ], index=['a', 'b', 'c']) } df_test = pd.DataFrame(d) I would like to compute…
Nick
  • 2,924
  • 4
  • 36
  • 43
8
votes
3 answers

Create an array with a pre determined mean and standard deviation

I am attempting to create an array with a predetermined mean and standard deviation value using Numpy. The array needs random numbers within it. So far I can produce an array and calculate the mean and std. but can not get the array to be controlled…
EORS
  • 89
  • 1
  • 1
  • 2
8
votes
2 answers

Assign group averages to each row in python/pandas

I have a dataframe and I am looking to calculate the mean based on store and all stores. I created code to calculate the mean but I am looking for a way that is more efficient. DF Cashier# Store# Sales Refunds 001 001 …
aiden rosenblatt
  • 403
  • 2
  • 5
  • 9
8
votes
1 answer

Mean Std in pandas data frame

Having a pandas data frame as follow: a b 0 1 12 1 1 13 2 1 23 3 2 22 4 2 23 5 2 24 6 3 30 7 3 35 8 3 55 I want to find the mean standard deviation of column b in each group. My following code give me 0 for each…
Elham
  • 827
  • 2
  • 13
  • 25
8
votes
2 answers

Conditional mean over a Pandas DataFrame

I have a dataset from which I want a few averages of multiple variables I created. I started off with: data2['socialIdeology2'].mean() data2['econIdeology'].mean() ^ that works perfectly, and gives me the averages I'm looking for. Now, I'm trying…
Oliver G
  • 1,021
  • 2
  • 9
  • 20
8
votes
3 answers

numpy mean of complex numbers with infinities

numpy seems to not be a good friend of complex infinities While we can evaluate: In[2]: import numpy as np In[3]: np.mean([1, 2, np.inf]) Out[3]: inf The following result is more cumbersome: In[4]: np.mean([1 + 0j, 2 + 0j, np.inf + 0j]) Out[4]:…
Aguy
  • 7,851
  • 5
  • 31
  • 58
8
votes
1 answer

Find Average of Every Three Columns in Pandas dataframe

I am new to Python and Pandas. I have a panda dataframe with monthly columns ranging from 2000 (2000-01) to 2016 (2016-06). I want to find the average of every three months and assign it to a new quarterly column (2000q1). I know I can do the…
Peyman
  • 91
  • 1
  • 4
8
votes
3 answers

Pandas: Fill missing values by mean in each group faster than transform

I need to fill missing values in a pandas DataFrame by the mean value in each group. According to this question transform can achieve this. However, transform is too slow for my purposes. For example, take the following setting with a large…
SmCaterpillar
  • 6,683
  • 7
  • 42
  • 70
8
votes
3 answers

Why do the results of mad(x) differ from the expected results?

I am trying to calculate the mean average deviation of a sample ("S") of numbers. The results I get when using the mad() function and when making the mean average deviation calculations one step at a time are different. Why? s<-…
8
votes
1 answer

using mean with .SD and .SDcols in data.table

I am writing a very simple function to summarize columns of data.tables. I am passing one column at a time to the function, and then doing some diagnostics to figure out the options for summarization, and then doing the summarization. I am doing…
Mark Danese
  • 2,331
  • 1
  • 20
  • 25
8
votes
3 answers

How to create mean and s.d. columns in data.table

The following code/outcome baffles me as to why data.table returns NA for the mean functions and not the sd function. library(data.table) test <- data.frame('id'=c(1,2,3,4,5), 'A'=seq(2,9,length=5), …
nfmcclure
  • 3,011
  • 3
  • 24
  • 40
8
votes
1 answer

Dealing with NaN when calculating means

I want to create a new column that contains the average two other columns. For example by original table (dat) looks like this: A B 1 1 NaN 2 3 2 3 2 5 4 4 4 5 6 NaN 6 5 3 I now want a column C that averages A and B,…
melanopygus
  • 131
  • 1
  • 1
  • 4
8
votes
4 answers

What is the most elegant way to calculate seasonal means with R?

I have evenly spaces timeseries with daily mean observational data. How do I compute seasonal means the easiest way? The seasons should follow the meteorological nomenclature with DJF (=winter: December, January, February), MAM, JJA, and SON. That…
stephan
  • 117
  • 2
  • 6
8
votes
1 answer

mean and median of residuals from a linear model

I just started to learn R and need some help on finding the mean and median of residuals for my data. I calculated the lm and in the summary I get residuals like follows: min 1Q median 3Q Max -111.86 -34.90 -7.6 33.46 …
michelle