Skip to main content
added 1110 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

Update

Show zero values and some other improvements

 data = 
   {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 33.9},
    {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 193.9},
    {{20131002}, 193.9}, {{20131022}, 193.9}};

Convert dates

dat = MapAt[DateList@*ToString@*First, data, {All, 1}]

{{{2012, 8, 2, 0, 0, 0.}, 193.9}, {{2012, 9, 12, 0, 0, 0.}, 493.9}...}

All months with default value zero - must start with year or quarter

amo = Transpose[{#, Array[0 &, {Length@#}]}] &[DateRange[{2012}, {2014}, "Month"]]

{{{2012, 1, 1}, 0}, {{2012, 2, 1}, 0} ... {{2014, 1, 1}, 0}}

DateListPlot[
 TimeSeriesAggregate[Join[dat, amo], {"Quarter", Left}, Count[#, _?Positive] &],
 DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
 Filling -> Bottom,
 GridLines -> Automatic,
 InterpolationOrder -> 0,
 PlotRange -> {{{2012, 4, 1}, {2013, 12, 1}}, Automatic},
 Mesh -> Full]

enter image description here

Original answer

To get an accurate aggregation we must start at {20120101}:

To get an accurate aggregation we must start at {20120101}:

Update

Show zero values and some other improvements

 data = 
   {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 33.9},
    {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 193.9},
    {{20131002}, 193.9}, {{20131022}, 193.9}};

Convert dates

dat = MapAt[DateList@*ToString@*First, data, {All, 1}]

{{{2012, 8, 2, 0, 0, 0.}, 193.9}, {{2012, 9, 12, 0, 0, 0.}, 493.9}...}

All months with default value zero - must start with year or quarter

amo = Transpose[{#, Array[0 &, {Length@#}]}] &[DateRange[{2012}, {2014}, "Month"]]

{{{2012, 1, 1}, 0}, {{2012, 2, 1}, 0} ... {{2014, 1, 1}, 0}}

DateListPlot[
 TimeSeriesAggregate[Join[dat, amo], {"Quarter", Left}, Count[#, _?Positive] &],
 DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
 Filling -> Bottom,
 GridLines -> Automatic,
 InterpolationOrder -> 0,
 PlotRange -> {{{2012, 4, 1}, {2013, 12, 1}}, Automatic},
 Mesh -> Full]

enter image description here

Original answer

To get an accurate aggregation we must start at {20120101}:

added 556 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

To get an accurate aggregation we must start at {20120101}:

 data =
  {{{20120101}, Missing[]}, {{20120802}, 193.9}, {{20120912}, 
   493.9}, {{20130412}, 
    33.9}, {{20130502}, 193.9}, {{20130802}, 
   193.9}, {{20130822}, 
    193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

FirstThen we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

ThenNow we use TimeseriesAggregate to count the frequency per quarter

  DateListPlot[
    TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],
 DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
 GridLines -> Automatic,
 PlotRange -> {{{2012, 8, 1}, {2013, 12, 31}}, Automatic},
 Mesh -> Full]

enter image description here

And here are the monthly figures

DateListPlot[
 TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Month", Length],
 DateTicksFormat -> {"Year", "/", "QuarterNameShort""Month"},
 GridLines -> Automatic,
 PlotRange -> {{{2012, 8, 1}, {2013, 10, 31}}, Automatic},
 Mesh -> Full]

enter image description hereenter image description here

data =
  {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 
    33.9}, {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 
    193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

First we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

Then we use TimeseriesAggregate to count the frequency per quarter

  DateListPlot[
    TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],
      DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
      Mesh -> Full]

enter image description here

To get an accurate aggregation we must start at {20120101}:

 data = {{{20120101}, Missing[]}, {{20120802}, 193.9}, {{20120912}, 
   493.9}, {{20130412}, 33.9}, {{20130502}, 193.9}, {{20130802}, 
   193.9}, {{20130822}, 193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

Then we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

Now we use TimeseriesAggregate to count the frequency per quarter

DateListPlot[
 TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],
 DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
 GridLines -> Automatic,
 PlotRange -> {{{2012, 8, 1}, {2013, 12, 31}}, Automatic},
 Mesh -> Full]

enter image description here

And here are the monthly figures

DateListPlot[
 TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Month", Length],
 DateTicksFormat -> {"Year", "/", "Month"},
 GridLines -> Automatic,
 PlotRange -> {{{2012, 8, 1}, {2013, 10, 31}}, Automatic},
 Mesh -> Full]

enter image description here

added 82 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202
data =
 {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 
    33.9}, {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 
    193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

First we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

Then we use TimeseriesAggregate to count the frequency per quarter

  DateListPlot[
    TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],
      DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
      Mesh -> Full]

enter image description hereenter image description here

data =
 {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 
    33.9}, {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 
    193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

First we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

Then we use TimeseriesAggregate to count the frequency per quarter

DateListPlot[
 TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],Mesh -> Full]

enter image description here

data =
 {{{20120802}, 193.9}, {{20120912}, 493.9}, {{20130412}, 
    33.9}, {{20130502}, 193.9}, {{20130802}, 193.9}, {{20130822}, 
    193.9}, {{20131002}, 193.9}, {{20131022}, 193.9}};

First we must transform the dates in a Mathematica-like form:

dates = 
  ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}], 
      StringTake[#, -2]}] & /@ (ToString /@ Flatten@data[[All, 1]]);

Then we use TimeseriesAggregate to count the frequency per quarter

  DateListPlot[
    TimeSeriesAggregate[Transpose[{dates, data[[All, 2]]}], "Quarter", Length],
      DateTicksFormat -> {"Year", "/", "QuarterNameShort"},
      Mesh -> Full]

enter image description here

added 137 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202
Loading
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202
Loading