Last active
July 2, 2019 20:18
-
-
Save Seanny123/1ad505e29aef86f13f8af683f0022305 to your computer and use it in GitHub Desktop.
Highlight missing date ranges given a Pandas DataFrame with a DateTimeIndex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_missing(df: pd.DataFrame, reg_diff, color="red"): | |
d_diff = np.diff(df.index) | |
gaps = d_diff > np.timedelta64(int(reg_diff), 'ns') | |
gap_sizes = d_diff[gaps] | |
for win_start, g_s in zip(df.index[:-1][gaps], gap_sizes): | |
win_end = win_start + g_s | |
plt.axvspan(win_start, win_end, color=color, alpha=.3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment