4
$\begingroup$

I have some twenty years of weather data with daily average temperature. I would like to make a histogram with aggregated monthly average for the whole period. I tried to do something like this https://www.wolfram.com/language/11/time-series-processing/trends-and-seasonalities.html?product=language But it didn’t work since my weights in WeightedData can be positive and negative. My data looks like this: enter image description here

data = {{"1965-12-01",0.5},{"1965-12-02",-4.1},{"1965-12-03",-0.8},{"1965-12-04",2.},{"1965-12-05",1.3},{"1965-12-06",0.4},{"1965-12-07",-6.6},{"1965-12-08",-3.9},{"1965-12-09",0.3},{"1965-12-10",1.2},{"1965-12-11",-3.},{"1965-12-12",-9.4},{"1965-12-13",-13.},{"1965-12-14",-10.5},{"1965-12-15",-4.6},{"1965-12-16",-6.5},{"1965-12-17",-8.},{"1965-12-18",-2.2},{"1965-12-19",1.7},{"1965-12-20",2.1},{"1965-12-21",-4.6},{"1965-12-22",-2.8},{"1965-12-23",-0.2},{"1965-12-24",-0.1},{"1965-12-25",0.9},{"1965-12-26",0.5},{"1965-12-27",-0.8},{"1965-12-28",-6.5},{"1965-12-29",-5.6},{"1965-12-30",-5.2},{"1965-12-31",-6.9},{"1966-01-01",-8.},{"1966-01-02",-4.2},{"1966-01-03",-7.3},{"1966-01-04",-12.9},{"1966-01-05",-12.},{"1966-01-06",-1.8},{"1966-01-07",-0.1},{"1966-01-08",-3.4},{"1966-01-09",-3.8},{"1966-01-10",-3.},{"1966-01-11",-3.8},{"1966-01-12",-5.3},{"1966-01-13",-5.9},{"1966-01-14",-7.9},{"1966-01-15",-6.2},{"1966-01-16",-8.},{"1966-01-17",-7.5},{"1966-01-18",-4.4},{"1966-01-19",-13.3},{"1966-01-20",-8.2},{"1966-01-21",-6.1},{"1966-01-22",-3.9},{"1966-01-23",-5.6},{"1966-01-24",-8.3},{"1966-01-25",-4.2},{"1966-01-26",-5.2},{"1966-01-27",-3.5},{"1966-01-28",-6.7},{"1966-01-29",-4.1},{"1966-01-30",1.3},{"1966-01-31",2.2},{"1966-02-01",-5.4},{"1966-02-02",-13.9},{"1966-02-03",-11.8},{"1966-02-04",-13.7},{"1966-02-05",-7.4},{"1966-02-06",-9.5},{"1966-02-07",-15.3},{"1966-02-08",-24.4},{"1966-02-09",-23.},{"1966-02-10",-12.8},{"1966-02-11",-19.2},{"1966-02-12",-20.2},{"1966-02-13",-18.1},{"1966-02-14",-11.1},{"1966-02-15",-13.},{"1966-02-16",-14.6},{"1966-02-17",-16.5},{"1966-02-18",-15.5},{"1966-02-19",-17.5},{"1966-02-20",-7.4},{"1966-02-21",0.6},{"1966-02-22",-0.7},{"1966-02-23",-1.1},{"1966-02-24",1.5},{"1966-02-25",0.2},{"1966-02-26",0.4},{"1966-02-27",1.4},{"1966-02-28",1.6},{"1966-03-01",-0.4},{"1966-03-02",-0.5},{"1966-03-03",2.9},{"1966-03-04",1.9},{"1966-03-05",1.1},{"1966-03-06",1.3},{"1966-03-07",2.1},{"1966-03-08",2.8},{"1966-03-09",0.7},{"1966-03-10",-0.2},{"1966-03-11",-0.5},{"1966-03-12",-6.4},{"1966-03-13",-8.2},{"1966-03-14",-7.8},{"1966-03-15",-5.6},{"1966-03-16",0.7},{"1966-03-17",4.},{"1966-03-18",0.4},{"1966-03-19",-1.8},{"1966-03-20",2.6},{"1966-03-21",3.1},{"1966-03-22",1.8},{"1966-03-23",2.},{"1966-03-24",0.3},{"1966-03-25",-3.1},{"1966-03-26",-4.9},{"1966-03-27",-1.5},{"1966-03-28",0.6},{"1966-03-29",0.6},{"1966-03-30",-0.2},{"1966-03-31",0.4},{"1966-04-01",0.9},{"1966-04-02",0.8},{"1966-04-03",4.},{"1966-04-04",2.2},{"1966-04-05",0.8},{"1966-04-06",1.8},{"1966-04-07",2.3},{"1966-04-08",2.2},{"1966-04-09",1.3},{"1966-04-10",-1.3},{"1966-04-11",-3.6},{"1966-04-12",-4.5},{"1966-04-13",-4.6},{"1966-04-14",-4.4},{"1966-04-15",-3.6},{"1966-04-16",-4.5},{"1966-04-17",-3.5},{"1966-04-18",-2.5},{"1966-04-19",0.},{"1966-04-20",0.4},{"1966-04-21",3.3},{"1966-04-22",1.7},{"1966-04-23",1.4},{"1966-04-24",3.8},{"1966-04-25",4.6},{"1966-04-26",4.9},{"1966-04-27",3.1},{"1966-04-28",6.7},{"1966-04-29",7.9},{"1966-04-30",8.5},{"1966-05-01",8.7},{"1966-05-02",8.9},{"1966-05-03",9.5},{"1966-05-04",6.7},{"1966-05-05",4.5},{"1966-05-06",1.7},{"1966-05-07",4.1},{"1966-05-08",6.7},{"1966-05-09",5.9},{"1966-05-10",8.},{"1966-05-11",8.},{"1966-05-12",6.1},{"1966-05-13",6.8},{"1966-05-14",9.4},{"1966-05-15",10.7},{"1966-05-16",9.5},{"1966-05-17",10.7},{"1966-05-18",13.3},{"1966-05-19",10.5},{"1966-05-20",8.3},{"1966-05-21",8.3},{"1966-05-22",8.8},{"1966-05-23",9.},{"1966-05-24",8.9},{"1966-05-25",8.9},{"1966-05-26",8.},{"1966-05-27",9.4},{"1966-05-28",10.7},{"1966-05-29",10.},{"1966-05-30",11.9},{"1966-05-31",12.},{"1966-06-01",10.9},{"1966-06-02",13.},{"1966-06-03",9.5},{"1966-06-04",10.2},{"1966-06-05",12.3},{"1966-06-06",12.8},{"1966-06-07",10.8},{"1966-06-08",11.5},{"1966-06-09",14.3},{"1966-06-10",15.6},{"1966-06-11",17.4},{"1966-06-12",18.3},{"1966-06-13",18.9},{"1966-06-14",18.7},{"1966-06-15",19.1},{"1966-06-16",19.7},{"1966-06-17",21.4},{"1966-06-18",21.5},{"1966-06-19",21.5},{"1966-06-20",19.1},{"1966-06-21",16.7},{"1966-06-22",15.7},{"1966-06-23",17.1},{"1966-06-24",17.2},{"1966-06-25",15.1},{"1966-06-26",15.1},{"1966-06-27",14.7},{"1966-06-28",13.9},{"1966-06-29",18.7},{"1966-06-30",16.5},{"1966-07-01",17.1},{"1966-07-02",17.1},{"1966-07-03",15.2},{"1966-07-04",16.3},{"1966-07-05",15.},{"1966-07-06",16.4},{"1966-07-07",14.2},{"1966-07-08",15.3},{"1966-07-09",17.5},{"1966-07-10",16.5},{"1966-07-11",15.2},{"1966-07-12",15.6},{"1966-07-13",15.2},{"1966-07-14",14.2},{"1966-07-15",13.8},{"1966-07-16",15.3},{"1966-07-17",15.1},{"1966-07-18",17.3},{"1966-07-19",18.8},{"1966-07-20",20.2},{"1966-07-21",21.},{"1966-07-22",22.3},{"1966-07-23",18.9},{"1966-07-24",17.4},{"1966-07-25",17.2},{"1966-07-26",14.6},{"1966-07-27",15.6},{"1966-07-28",15.8},{"1966-07-29",15.4},{"1966-07-30",14.},{"1966-07-31",14.2},{"1966-08-01",14.7},{"1966-08-02",13.7},{"1966-08-03",14.7},{"1966-08-04",13.1},{"1966-08-05",15.},{"1966-08-06",14.2},{"1966-08-07",15.9},{"1966-08-08",15.2},{"1966-08-09",15.7},{"1966-08-10",15.5},{"1966-08-11",15.1},{"1966-08-12",14.9},{"1966-08-13",14.1},{"1966-08-14",15.1},{"1966-08-15",13.9},{"1966-08-16",13.4},{"1966-08-17",15.6},{"1966-08-18",16.},{"1966-08-19",16.1},{"1966-08-20",15.},{"1966-08-21",14.4},{"1966-08-22",13.8},{"1966-08-23",14.4},{"1966-08-24",13.6},{"1966-08-25",14.8},{"1966-08-26",13.},{"1966-08-27",13.5},{"1966-08-28",15.2},{"1966-08-29",15.5},{"1966-08-30",13.8},{"1966-08-31",14.6},{"1966-09-01",14.4},{"1966-09-02",14.1},{"1966-09-03",14.7},{"1966-09-04",14.8},{"1966-09-05",15.6},{"1966-09-06",14.3},{"1966-09-07",15.3},{"1966-09-08",13.6},{"1966-09-09",8.7},{"1966-09-10",10.8},{"1966-09-11",13.6},{"1966-09-12",12.6},{"1966-09-13",14.1},{"1966-09-14",13.5},{"1966-09-15",13.},{"1966-09-16",10.2},{"1966-09-17",12.3},{"1966-09-18",7.8},{"1966-09-19",10.9},{"1966-09-20",14.7},{"1966-09-21",12.2},{"1966-09-22",9.4},{"1966-09-23",9.1},{"1966-09-24",12.5},{"1966-09-25",7.1},{"1966-09-26",10.5},{"1966-09-27",5.3},{"1966-09-28",3.5},{"1966-09-29",7.1},{"1966-09-30",10.5},{"1966-10-01",9.3},{"1966-10-02",11.4},{"1966-10-03",11.6},{"1966-10-04",11.1},{"1966-10-05",4.6},{"1966-10-06",7.5},{"1966-10-07",9.6},{"1966-10-08",11.4},{"1966-10-09",9.1},{"1966-10-10",6.5},{"1966-10-11",7.4},{"1966-10-12",6.},{"1966-10-13",6.1},{"1966-10-14",6.3},{"1966-10-15",8.7},{"1966-10-16",10.5},{"1966-10-17",11.2},{"1966-10-18",10.},{"1966-10-19",9.3},{"1966-10-20",9.6},{"1966-10-21",9.8},{"1966-10-22",9.6},{"1966-10-23",8.8},{"1966-10-24",7.4},{"1966-10-25",1.8},{"1966-10-26",3.4},{"1966-10-27",4.6},{"1966-10-28",0.5},{"1966-10-29",-1.4},{"1966-10-30",2.6},{"1966-10-31",6.5},{"1966-11-01",4.5},{"1966-11-02",3.1},{"1966-11-03",2.8},{"1966-11-04",4.},{"1966-11-05",7.},{"1966-11-06",6.7},{"1966-11-07",6.1},{"1966-11-08",7.6},{"1966-11-09",7.6},{"1966-11-10",3.6},{"1966-11-11",-0.5},{"1966-11-12",1.},{"1966-11-13",4.3},{"1966-11-14",6.4},{"1966-11-15",4.5},{"1966-11-16",3.6},{"1966-11-17",3.1},{"1966-11-18",2.2},{"1966-11-19",0.},{"1966-11-20",0.9},{"1966-11-21",3.1},{"1966-11-22",1.4},{"1966-11-23",1.5},{"1966-11-24",2.8},{"1966-11-25",2.8},{"1966-11-26",3.6},{"1966-11-27",5.},{"1966-11-28",5.4},{"1966-11-29",1.4},{"1966-11-30",1.7}};

Any help would be much appreciated

$\endgroup$
  • $\begingroup$ Is this unique data or can they be repeated using AirTemperatureData[]? $\endgroup$ – Alex Trounev Jan 27 at 14:30
  • $\begingroup$ The data comes from an external source. $\endgroup$ – supernasse Jan 27 at 14:40
  • $\begingroup$ Maybe use the temperature in Kelvin? $\endgroup$ – FredrikD Jan 27 at 15:08
  • $\begingroup$ Hi @supernasse, welcome to the mathematica Stack Exchange. Please consider adding a sample of your data to your question as copy-pasteable text so that we can help you easier. In the meantime, try to create a TimeSeries of your data and use TimeSeriesAggregate. $\endgroup$ – Carl Lange Jan 27 at 15:18
  • 1
    $\begingroup$ @supernasse I've significantly modified my answer, please take a look! $\endgroup$ – Carl Lange Jan 27 at 17:30
4
$\begingroup$

We need to manually group the data by month and take its mean, like so:

BarChart[GroupBy[data, DateValue[First@#, "MonthNameShort"] &, 
  Extract[{All, 2}] /* Mean], ChartLabels -> Automatic]

To break this down: First, we GroupBy the month (DateValue[First@#, "MonthNameShort"]). Then we extract the second part of every value: Extract[{All, 2}] and then take the Mean.

enter image description here

We can now extend this to do it over weekdays for example:

BarChart[GroupBy[data, DateValue[First@#, "DayNameShort"] &, 
  Extract[{All, 2}] /* Mean], ChartLabels -> Automatic]

enter image description here

or any other period really:

enter image description here

Check the documentation for DateValue for the various different groupings. It's perhaps more useful if your data is higher resolution (for instance, down to the hour) but in any case, this is a nice, extensible solution.

Finally, you can modify what function you want to reduce your data by. You initially asked for Mean, but we could do other interesting things like the standard deviation, just by modifying the reduction function:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.