.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/data_quality/plot_rolling_stddev_timedelta.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_data_quality_plot_rolling_stddev_timedelta.py: ==================================================== Rolling standard deviation of data points time delta ==================================================== Example of visualizing rolling standard deviation of time delta of time series data to identify dispersion in the ingestion of data. .. GENERATED FROM PYTHON SOURCE LINES 10-51 .. image-sg:: /auto_examples/data_quality/images/sphx_glr_plot_rolling_stddev_timedelta_001.png :alt: Standard deviation of time delta :srcset: /auto_examples/data_quality/images/sphx_glr_plot_rolling_stddev_timedelta_001.png :class: sphx-glr-single-img .. code-block:: default from datetime import datetime, timedelta import matplotlib.pyplot as plt import numpy as np import pandas as pd from indsl.data_quality.rolling_stddev import rolling_stddev_timedelta from indsl.smooth import sma data = pd.Series(1, index=pd.date_range(start="2022-01-01 10:00:00", end="2022-01-01 11:00:00", freq="1s")).sample(60) data = data.sort_index() time_window = pd.Timedelta(minutes=5) # Calculate rolling standard deviation of time delta stddev = rolling_stddev_timedelta(data, time_window=time_window).values # Calculate rolling mean of time delta mean = sma(data.index.to_series().diff().astype("timedelta64[s]").fillna(0), time_window="5min", min_periods=1) # Plot standard deviation and mean fig, ax = plt.subplots(figsize=(15, 5)) ax.title.set_text("Standard deviation of time delta") ax.plot(data.index, stddev, label="Standard deviation", marker=".") ax.plot(data.index, mean, label="Mean", marker=".") values = np.arange(data.index[0], data.index[-1], timedelta(minutes=4)).astype(datetime) ax.set_xticks(values) ax.set_xticklabels([ts.strftime("%d-%m-%Y \n %H:%M:%S") for ts in values], fontsize=8) legend = ax.legend(loc="upper right") plt.xlabel("Timestamp") plt.ylabel("Standard deviation") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.000 seconds) .. _sphx_glr_download_auto_examples_data_quality_plot_rolling_stddev_timedelta.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rolling_stddev_timedelta.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rolling_stddev_timedelta.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_