Convert 'WeekDate' to datetime format datasetlowvolume = datasetlowvolume.withcolumns(…
- User
Convert 'WeekDate' to datetime format
dataset_lowvolume = dataset_lowvolume.with_columns( pl.col("WeekDate").str.strptime(pl.Datetime, "%Y-%m-%d") )
Group by 'CL4' and 'WeekDate', then sum 'OrderQuantity'
y_cl4 = dataset_lowvolume.groupby(['MaterialID', 'SalesOrg', 'DistrChan', 'CL4', 'WeekDate']).agg( pl.sum("OrderQuantity").alias("OrderQuantity") )
Sort by 'WeekDate'
y_cl4 = y_cl4.sort("WeekDate") # Get the number of rows in y num_rows = y_cl4.shape[0] print(f"Number of rows in y: {num_rows}") now fix this code, y_cl4 = y_cl4.rename({'WeekDate': 'ds', 'CL4': 'unique_id', 'OrderQuantity': 'y'}) the unique_id should be combination of these 4 'MaterialID', 'SalesOrg', 'DistrChan', 'CL4', how should I do it? may be concat? using polars only
- Assistant
In Polars, if you want to concatenate multiple columns into a single column to create a unique identifier, you could use the
concat_strfunction. This function takes an array of column names as argument, which are then concatenated together with an optional separator string.