'How can I automate the plotting of multiple 'chunks' of data from a very large time-series using Pandas?

My goal is to be able to produce a time-series plot for every event in 'event.csv' from a large time-series dataset called 'parsed.csv'.

I am able to successfully plot a single event by manually defining the desired time range for an event with a +/- 12 hour buffer as desired. There are hundreds of events, making automation of some sort necessary. I am very new to loops/automation and have been extremely stuck.

Code:

import matplotlib.pyplot as plt
import pandas as pd

df_event = pd.read_csv('event.csv',parse_dates['Date_Time'],index_col= ['Date_Time'])
df = pd.read_csv('parsed.csv',parse_dates=['Date_Time'],index_col= ['Date_Time'])

df.Verified = pd.to_numeric(df.Verified, errors='coerce')          #forces columns to float64 dtype
df.dropna(axis='index',how='any',inplace=True)                     #fixes any null values



df = df.loc['2018-05-01':'2018-05-06']                            #can manually define event using this


fig, axs = plt.subplots(figsize=(12, 6))                          #define axis, and plots
df.plot(ax=axs)



Sample of my large time-series csv dataset:

                        Predicted  Verified
Date_Time                               
2010-01-01 00:00:00      5.161      5.56
2010-01-01 00:06:00      5.187      5.57
2010-01-01 00:12:00      5.208      5.56
2010-01-01 00:18:00      5.222      5.55
2010-01-01 00:24:00      5.230      5.53
                       ...       ...
2020-12-31 23:30:00      3.342      3.81
2020-12-31 23:36:00      3.447      3.92
2020-12-31 23:42:00      3.549      4.03
2020-12-31 23:48:00      3.646      4.14
2020-12-31 23:54:00      3.739      4.24



Event.csv sample:

                        Verified
Date_Time                               
2010-01-06 12:05:00      5.161      
2010-03-13 02:06:00      5.187      
2010-07-24 06:13:00      5.208      







Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source