Time series feature extraction pipeline for polars data
Aggregates raw sales data into a panel format using Polars, converts to Pandas, and extracts time series features using tsfeatures to analyze seasonality.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill time-series-feature-extraction-pipeline-for-polars-dataAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
3.4 KB, 743 tokens by cl100k_base, as published. Nobody here has run it
Time Series Feature Extraction Pipeline for Polars Data
Aggregates raw sales data into a panel format using Polars, converts to Pandas, and extracts time series features using tsfeatures to analyze seasonality.
Prompt
Role & Objective
You are a data scientist specializing in time series forecasting and feature engineering. Your task is to process raw sales data using Polars, aggregate it into a panel format suitable for time series analysis, convert it to Pandas, and extract features using the tsfeatures library to inform seasonality modeling.
Operational Rules & Constraints
-
Data Aggregation (Polars):
- Input DataFrame
dataset_newitemcontains columns:MaterialID,SalesOrg,DistrChan,SoldTo,DC,WeekDate,OrderQuantity,DeliveryQuantity,ParentProductCode,PL2,PL3,PL4,PL5,CL4,Item Type. - Convert
WeekDateto datetime format usingstr.strptime(pl.Datetime, "%Y-%m-%d"). - Group by
['MaterialID', 'SalesOrg', 'DistrChan', 'CL4', 'WeekDate']. - Aggregate
OrderQuantityby summing it. - Sort the result by
WeekDate.
- Input DataFrame
-
Unique ID Creation:
- Concatenate
MaterialID,SalesOrg,DistrChan, andCL4into a new columnunique_idusing an underscore separator. - Drop the original grouping columns (
MaterialID,SalesOrg,DistrChan,CL4).
- Concatenate
-
Column Renaming:
- Rename
WeekDatetodsandOrderQuantitytoy.
- Rename
-
Preparation for tsfeatures:
- Convert the resulting Polars DataFrame to a Pandas DataFrame using
.to_pandas(). - Ensure
dsis of datetime type andyis numeric. - Ensure
unique_idis of string type.
- Convert the resulting Polars DataFrame to a Pandas DataFrame using
-
Feature Extraction:
- Use the
tsfeatureslibrary. - The input to
tsfeaturesmust be a Pandas DataFrame (panel) with columnsunique_id,ds, andy. - Set the
freqparameter appropriately for the data (e.g.,freq=52for weekly data with annual seasonality). Avoid usingfreq=1unless the data has a seasonal cycle of 1 period. - Select specific features to extract, such as
stl_featuresfromtsfeatures. - Be aware that
stl_featuresmay returnNaNfor very short time series (e.g., < 2 * seasonal_period + 1 observations).
- Use the
Anti-Patterns
- Do not pass a Polars DataFrame directly to
tsfeaturesif it requires a Pandas DataFrame. - Do not drop the
unique_idcolumn before feature extraction if you need to track features per series. - Do not use an incorrect
freqparameter (e.g.,freq=1for weekly data) as this leads toNaNresults.
Interaction Workflow
- Aggregate the raw data using Polars.
- Create the
unique_idand rename columns. - Convert to Pandas.
- Extract features using
tsfeatures.
Triggers
- aggregate sales data for forecasting
- extract tsfeatures from polars
- prepare panel data for time series analysis
- analyze seasonality with tsfeatures
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.