Groupby and period

Hello,

I have this dataset. I want to group by name and calculate the average of CLOSE over a 5-day period.
CAMBACERES.xlsx (34.9 KB)

For example :


Thanks
Br

@Brain

I’m not quite sure if understood the challenge correctly.
My idea would be to filter first for the time range (I assume that the latest day -4 until the latest day). The the ROW Filter Node KNIME Base nodes – KNIME Community Hub would be the right node
What you have now is the range you want to group and calculate with. For this you can use the Group By Node Basic Examples for using the GroupBy Node – KNIME Community Hub

HTH

1 Like

Have built a prototype that I think does what you need:

Prototype:
5drollingclose.knwf (151.8 KB)

Overview:

  1. you iterate over each company in a group loop
  2. to avoid another loop I use some math logic to identify the “continuous groups” of 5 (1st col expression + missing values node)
  3. 2nd col expressions node creates your new “Date” by combining the year from original date and the group ID
  4. group by node groups by company + new ID field and calculates the mean for close
  5. collect data for each company

Note: the last “group” may not be based of 5 values - e.g. if you have 17 values for one company, groups 1-3 will be based on 5 data points and the 4th group will be based on only the remaining two.

3 Likes

Perfect
Many Thanks
Br

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.