Finding average using function forEach

How can I find the average of an object(number) using function forEach? var people =[{ name = "John" number = "283.37" },{ name = "Susan" number = "125,44" },{ name = "Karen" number = "98,7" }]; var sum = 0; people.forEach(function(num) { sum += num}); average = sum / people.length; console.log(average); I get the Nan… Read More Finding average using function forEach

Finding average of the numbers in each line Python

I have a program which grabs the drivers laptimes and writes them to a txt file. output.txt looks like this: 00:01:26.102 00:01:15.618 00:01:15.096 00:01:14.792 00:01:14.532 00:01:25.083 00:01:25.497 00:01:17.809 00:01:19.364 00:01:18.935 00:01:18.076 00:01:18.111 00:01:22.086 00:01:20.500 00:01:18.167 00:01:18.268 00:01:18.373 00:01:17.950 00:01:17.944 I want to sum all the lap times and divide it by lap count(basically find the… Read More Finding average of the numbers in each line Python

How to combine different rows and get mean value for columns in a dataframe

I have the following df which contains 2 types of information. The first one is the characteristics of the item (some are strings and others are integers). The other type is regarding emission values of the said item (in a float format). Charact. 1 Charact. 2 Charact. 3 Emission 1 Emission 2 1998 AB C… Read More How to combine different rows and get mean value for columns in a dataframe

How to consider values from arrays and do averaging when array has nan values?

I have two arrays (A and B) containing either values ore nan’s. For calculating the average, I sum both up and divide by two. A: array([ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 109.93013333, 121.27613333, 131.6136 , 142.32926667, 148.2544 , 156.32266667, 160.3568 , 164.39093333, 168.6772 , 165.2734 , 165.77766667, 163.0042 , 164.8952… Read More How to consider values from arrays and do averaging when array has nan values?

Pandas – calculate monthly average from data with mixed frequencies

Suppose I have a dataset consisting of monthly, quarterly and annual average occurrences of an event: multi_index = pd.MultiIndex.from_tuples([("2022-01-01", "2022-12-31"), ("2022-01-01", "2022-03-30"), ("2022-03-01", "2022-03-30"), ("2022-04-01", "2022-04-30")]) multi_index.names = [‘period_begin’, ‘period_end’] df = pd.DataFrame(np.random.randint(10, size=4), index=multi_index) df 0 period_begin period_end 2022-01-01 2022-12-31 4 2022-03-30 3 2022-03-01 2022-03-30 5 2022-04-01 2022-04-30 8 I want to calculate the… Read More Pandas – calculate monthly average from data with mixed frequencies

Dplyr – Get Running average per entity based on a filter

dput of the input dataframe : structure(list(Entity = c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B" ), Date = structure(c(1640995200, 1641081600, 1641168000, 1641254400, 1641340800, 1641427200, 1641513600, 1641600000, 1641686400, 1641772800, 1640995200, 1641081600, 1641168000, 1641254400, 1641340800, 1641427200, 1641513600, 1641600000, 1641686400, 1641772800), tzone = "UTC", class… Read More Dplyr – Get Running average per entity based on a filter