feature-engine / feature_engine

Feature engineering package with sklearn like functionality
https://feature-engine.trainindata.com/
BSD 3-Clause "New" or "Revised" License
1.8k stars 303 forks source link

New feature: Lag or windows features grouped by #668

Open scardonal opened 1 year ago

scardonal commented 1 year ago

Is your feature request related to a problem? Please describe. For example, you want to create lag features of sales for a retail chain, but taking into account the stores, product categories, and date. It's widespread to create lag features taking into consideration the hierarchy or grouping levels.

Describe the solution you'd like I would like the la feature creation but apply groups by different columns in the data frame.

Describe alternatives you've considered An alternative solution would be to create a sklearn transformer class to apply the groupby and lag functions of pandas.

Here is an example of what I'm talking about using pandas: https://www.statology.org/pandas-lag-by-group/

candalfigomoro commented 1 year ago

I have time series identified by an id column, and I would also need to create lag features for each group id.

Moreover, in addition to the id column, it would be useful to be able to pass the name of a column to use for sorting within each group (e.g., a datetime column) instead of just having the "sort_index" parameter.