Socket
Book a DemoInstallSign in
Socket

pd-window-decorators

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pd-window-decorators

A decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.

0.0.1
pipPyPI
Maintainers
1

pd-window-decorators

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.

Sliding Window

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.

Example

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.

Arguments

ArgumentTypeOptionalDescription
window_sizetimedeltaTrueThe size of the window to apply to the function.
df_namestrFalseThe name of the DataFrame variable to pass to the function as an argument. Defaults to df.
time_columnstrFalseThe name of the column in the DataFrame that contains the time information. Defaults to ds.

Keywords

pandas

FAQs

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.