
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
pd-window-decorators
Advanced tools
A decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.
Easily apply windowing to functions that mutate Pandas DataFrames. Useful for data science projects where you want to apply a function for a DataFrame using smaller chunks of the DataFrame automatically. A moving window can be easily applied to the function using Python decorators.
To apply a sliding window, import df_sliding_window
from pd_window_decorators
and apply it to your function. The decorator takes a timedelta
object as a required argument to define the slice size. By default, the decorator will look for a Pandas DataFrame named df
in the function arguments. The DataFrame must also have a time column. The column name is ds
by default. The decorator also expects the function to return a DataFrame.
Using the decorator with default arguments:
@df_sliding_window(window_size=timedelta(days=2))
def sum_all(df):
df.loc[:, 'sum'] = df['y'].sum()
return df
Using the decorator with custom arguments:
@df_sliding_window(window_size=timedelta(days=2), df_name='my_df', time_column='my_time')
def sum_all(my_df):
df.loc[:, 'sum'] = df['y'].sum()
return df
Note that in the second example, the DataFrame is named my_df
and the df_name
argument is set to my_df
, so they match.
Argument | Type | Optional | Description |
---|---|---|---|
window_size | timedelta | True | The size of the window to apply to the function. |
df_name | str | False | The name of the DataFrame variable to pass to the function as an argument. Defaults to df . |
time_column | str | False | The name of the column in the DataFrame that contains the time information. Defaults to ds . |
FAQs
A decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.
We found that pd-window-decorators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.