mean

Find the average of last 25% from the input range in pandas

Find the average of last 25% from the input range in pandas Question: I have successfully imported temperature CSV file to Python Pandas DataFrame. I have also found the mean value of specific range: df.loc[7623:23235, ‘Temperature’].mean() where ‘Temperature’ is Column title in DataFrame. I would like to know if it is possible to change this …

Total answers: 2

Why is a combination of numpy functions faster than np.mean?

Why is a combination of numpy functions faster than np.mean? Question: I am wondering what the fastest way for a mean computation is in numpy. I used the following code to experiment with it: import time n = 10000 p = np.array([1] * 1000000) t1 = time.time() for x in range(n): np.divide(np.sum(p), p.size) t2 = …

Total answers: 2

pass custom scaling operation in python

pass custom scaling operation in python Question: i am following an example of the https://github.com/google/lightweight_mmm but instead of using the default setting for scalars, which is mean: media_scaler = preprocessing.CustomScaler(divide_operation=jnp.mean) i need to use the lambda function: lambda x: jnp.mean(x[x > 0]) How can this be done? I tried couple of things, but since i …

Total answers: 1

Pandas; Need to combine duplicate columns, and find the mean of another column

Pandas; Need to combine duplicate columns, and find the mean of another column Question: I have this data frame with about 200 rows, and I need to combine the duplicate writers columns, and then find the mean value of their viewership. How can I accomplish this? Below is a sample of the data frame. Viewership …

Total answers: 1

pandas average across dynamic number of columns

pandas average across dynamic number of columns Question: I have a dataframe like as shown below customer_id revenue_m7 revenue_m8 revenue_m9 revenue_m10 1 1234 1231 1256 1239 2 5678 3425 3255 2345 I would like to do the below a) get average of revenue for each customer based on latest two columns (revenue_m9 and revenue_m10) b) …

Total answers: 2

How do I take the average (mean) of inputted numbers in Python?

How do I take the average (mean) of inputted numbers in Python? Question: I would like to take create a code that takes an input of numbers, and then takes the average (mean) of these numbers. So far, I have this: from statistics import mean numbers=int(input("Enter some numbers. Seperate each number by a space: ") …

Total answers: 4

random float numbers and their mean and standart deviation

random float numbers and their mean and standart deviation Question: how to get a list of 1000 random float numbers without dublicates and find their mean value in python? import random rnd_number=random.random() def a(): l=[] m=1 for i in range(1000): l.append(rnd_number) return l for i in l: m=m+i return m//b print (a()) i am probably …

Total answers: 3

Replace NaN with the average of the last 5 values – Pandas

Replace NaN with the average of the last 5 values – Pandas Question: I want to know how can I replace the NaN in my dataset with the last average of 5 last values. Column A Column B 1 2 2 5 3 5 4 2 5 2 NaN 2 NaN 2 1 2 1 …

Total answers: 1