1

I'm trying to graph date and time data, but I have know idea how. I've heard of the libraries pandas and matplotlib, but I don't know how to graph time or date data, much less them together. Here is a sample dataset:

    x-axis       y-axis
Oct 17, 2017    19:38.00
Oct 14, 2017    19:06.05
Oct 7, 2017     19:12.00
Sep 30, 2017    19:37.15
Sep 27, 2017    21:37.00
Sep 22, 2017    21:26.65
Sep 20, 2017    21:35.55
Sep 8, 2017     21:30.56
Sep 1, 2017     21:21.20
Aug 22, 2017    23:56.05
Peter S
  • 827
  • 1
  • 8
  • 24

1 Answers1

0

Once you convert columns to pandas date and timedelta (or seconds), that should be enough:

In [11]: df["x-axis"] = pd.to_datetime(df["x-axis"])

In [12]: df["y-axis"] = pd.to_timedelta(df["y-axis"].str.replace(".", ":")).astype('timedelta64[s]')

In [13]: df.plot(x="x-axis", y="y-axis")
Out[13]: <matplotlib.axes._subplots.AxesSubplot at 0x1131769e8>

See also Plotting pandas timedelta.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535