mean

How do I write a function that returns mean, median and trimmed mean in python?

How do I write a function that returns mean, median and trimmed mean in python? Question: I am attempting to write a function that will give me an output of mean, median and trimmed mean depending on what is chosen. This is the problem: Suppose x is a vector. Write a function f(x,type) where the …

Total answers: 1

aggregate statistic on pyspark columns, handling nulls

aggregate statistic on pyspark columns, handling nulls Question: I have a trivial question regarding the aggregate statistic on sparkpyspark I was not able to find an answer here on stack overflow, neither on the doc Assuming a column like this one: |COL | |null | |null | |null | |14.150919 | |1.278803 | |null | …

Total answers: 1

Make multiple means from one column with pandas

Make multiple means from one column with pandas Question: With Python 3.10 Sample data: import pandas as pd data = [[1, 14890, 3], [4, 5, 6], [7, 8, 9], [11, 13, 14], [12, 0, 18], [87, None, 54], [1, 0, 3], [4, 5, 6], [7, 8, 9], [11, 13, 14], [12, 0, 18], [87, None, …

Total answers: 1

calculate mean of new list of number with old mean

calculate mean of new list of number with old mean Question: I have a requirement to update the existing mean when new set of data is coming. For example, Say I have already calculated mean of a list of numbers and kept. from statistics import mean l1=[1,0,1,0,0,0,0,1,1,1,0,1] m1=mean(l1) print(m1) 0.5 Then say I get a …

Total answers: 2

groupby with diff function

groupby with diff function Question: I have a groupby with a diff function, however I want to add an extra mean column for heart rate, how can I do this the best way? this is the code data= pd.DataFrame( [[Timestamp(‘2022-08-05 10:11:04’), 140, 120], [Timestamp(‘2022-08-05 10:11:05’), 160, 155], [Timestamp(‘2022-08-05 10:11:06’), 230, 156], [Timestamp(‘2022-08-05 10:11:07’), 230, 155], …

Total answers: 1

Pandas Dataframe – Fillna with Mean by Month

Pandas Dataframe – Fillna with Mean by Month Question: I have a dataframe with som "NaN" and Outlier values which I want to fill with the mean value of the specific month. df[["arrival_day", "ib_units", "month","year"]] arrival_day ib_units month year 37 2020-01-01 262 1 2020 235 2020-01-02 2301 1 2020 290 2020-01-02 145 1 2020 476 …

Total answers: 2

python pandas column with averages

python pandas column with averages Question: I have a dataframe with in column "A" locations and in column "B" values. Locations occure multiple times in this DataFrame, now i’d like to add a third column in which i store the average value of column "B" that have the same location value in column "A". -I …

Total answers: 4

how to compute mean absolute deviation row wise in pandas

how to compute mean absolute deviation row wise in pandas Question: snippet of the dataframe is as follows. but actual dataset is 200000 x 130. ID 1-jan 2-jan 3-jan 4-jan 1. 4 5 7 8 2. 2 0 1 9 3. 5 8 0 1 4. 3 4 0 0 I am trying to compute …

Total answers: 3