How to obtain the arithmetic mean, minimum and maximum of all columns of a data frame in Julia?

Viewed 107

For the following data frame in Julia, containing noon temperatures (in degree Celsius) for 4 cities on 6 consecutive days, I want to find the arithmetic mean, minimum and maximum temperature of each city.

using DataFrames
city_temperature = DataFrame(City_1 = [27, 27, 29, 26, 24, 21],
             City_2 = [30, 31, 29, 30, 33, 30], 
             City_3 = [25, 26, 25, 28, 27, 28], 
             City_4 = [28, 29, 32, 34, 33, 35]);
city_temperature

6×4 DataFrame
│ Row │ City_1 │ City_2 │ City_3 │ City_4 │
│     │ Int64  │ Int64  │ Int64  │ Int64  │
├─────┼────────┼────────┼────────┼────────┤
│ 1   │ 27     │ 30     │ 25     │ 28     │
│ 2   │ 27     │ 31     │ 26     │ 29     │
│ 3   │ 29     │ 29     │ 25     │ 32     │
│ 4   │ 26     │ 30     │ 28     │ 34     │
│ 5   │ 24     │ 33     │ 27     │ 33     │
│ 6   │ 21     │ 30     │ 28     │ 35     │
1 Answers

The describe() function in DataFrames in Julia might help:

using DataFrames    
city_temperature = DataFrame(City_1 = [27, 27, 29, 26, 24, 21],
             City_2 = [30, 31, 29, 30, 33, 30], 
             City_3 = [25, 26, 25, 28, 27, 28], 
             City_4 = [28, 29, 32, 34, 33, 35]);
describe(city_temperature, :mean, :min, :max)

4×4 DataFrame
│ Row │ variable │ mean    │ min   │ max   │
│     │ Symbol   │ Float64 │ Int64 │ Int64 │
├─────┼──────────┼─────────┼───────┼───────┤
│ 1   │ City_1   │ 25.6667 │ 21    │ 29    │
│ 2   │ City_2   │ 30.5    │ 29    │ 33    │
│ 3   │ City_3   │ 26.5    │ 25    │ 28    │
│ 4   │ City_4   │ 31.8333 │ 28    │ 35    │
Related