0

I have results of sport event(run) as lap times. The time is in format of H:M:S(00:49:51). I have plotted the most common finishing time like this:

df['new_time'] = pd.to_timedelta(df['time'], errors='coerce')
time_frame = str(60 * 5) + 's'
lap_time = df.groupby(pd.Grouper(key='new_time', freq=time_frame)).count()
lap_time['count'].plot()

and it works fine.enter image description here

But I want to draw red line or mark, where would my result time(01:07:45) be.Other option would also be to change the plot to bars and just color that one bar red where my time would be groupbed in.

EDIT: This is double question. The probelm was that Pandas represents Timedeltas in nanosecond resolution using 64 bit integers and thats why it didn't show up.

pinq-
  • 367
  • 2
  • 17

1 Answers1

0

Pandas uses matplotlib, so you can use their functions here. Add the following lines to your code:

df['new_time'] = pd.to_timedelta(df['time'], errors='coerce')
time_frame = str(60 * 5) + 's'
lap_time = df.groupby(pd.Grouper(key='new_time', freq=time_frame)).count()
ax = lap_time['count'].plot()

ymin, ymax = ax.get_ylim()
date # make date be equal to whatever you are storing in your DataFrame
# If it is of type; datetime.time, then the following should work
# date = pd.to_datetime('01:07:45').time()
ax.vlines(x=date, ymin=ymin, ymax=ymax-1, color='r')
Akaisteph7
  • 5,034
  • 2
  • 20
  • 43