Python: How to plot time interval from a Dataframe in Pandas

I have the a dataframe(df) which has the data of a Job being executed at different time intervals. It includes the following details about the execution of a job:

  1. Job Start Time (START)
  2. Job End Time (END)
  3. Time Interval (interval) i.e., END - START.

A small part of dataframe is shown below.

Dataframe(df):

  END    |  START   |  interval
1423.0   |  1357.0  |    66.0
33277.0  |  33325.0 |   -48.0
42284.0  |  42250.0 |    34.0
53466.0  |  53218.0 |   248.0
62158.0  |  62073.0 |    85.0

I want to plot a graph with the x-axis as the timestamp and the y-axis with the interval. I tried to do it with the START time but it is not giving the correct result. How can we do this?

Code

fig_dims = (12, 10)
fig, ax = plt.subplots(figsize=fig_dims)

sns.lineplot(x = 'START', y = 'interval', data = df, ax = ax)

Output

Required Output

x-axis - Timestamp

y-axis - Interval

Topic matplotlib dataframe seaborn pandas python

Category Data Science


Some suggested alternative plotting methods to visualise this data:

  1. Histogram of the y-axis. Check the distribution of time intervals

    df.plot.hist(by='interval', bins=10) #test varying the bin size

  2. Plot smaller subsets of the data if the order is important e.g. df[:100].plot() furthermore, if there is periodicity in the data, e.g. daily, hourly etc. you could plot each hour on top of each other (in a different colour) to compare the differences between periods.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.