3 examples of 'pandas lag function' in Python

Every line of 'pandas lag function' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
384def lag_plot(series, lag=1, ax=None, **kwds):
385 """
386 Lag plot for time series.
387
388 Parameters
389 ----------
390 series : Time series
391 lag : lag of the scatter plot, default 1
392 ax : Matplotlib axis object, optional
393 **kwds
394 Matplotlib scatter method keyword arguments.
395
396 Returns
397 -------
398 class:`matplotlib.axis.Axes`
399 """
400 plot_backend = _get_plot_backend("matplotlib")
401 return plot_backend.lag_plot(series=series, lag=lag, ax=ax, **kwds)
109def add_lag_vars(df, lag=3):
110 new_df_dict = {}
111 for col_header in df.drop("Date", axis=1):
112 new_df_dict[col_header] = df[col_header]
113 for lag in range(1, lag + 1):
114 new_df_dict["%s_lag%d" %
115 (col_header, lag)] = df[col_header].shift(-lag)
116
117 new_df = pd.DataFrame(new_df_dict, index=df.index)
118 new_df["Date"] = df["Date"]
119
120 return new_df.dropna()
35def add_lag(self, df):
36 """Adds the lag to the index of the dataframe"""
37 df.index = df.index.map(self.add_date_lag)
38 return df

Related snippets