I have data that lists an activity for a time:
``Process Start Process End Duration Task
1/3/2016 4:07:47 PM 1/3/2016 4:08:09 PM 0:00:22 A
1/3/2016 4:08:09 PM 1/3/2016 4:08:19 PM 0:00:10 B
1/3/2016 4:08:19 PM 1/3/2016 4:08:27 PM 0:00:08 C
1/3/2016 4:08:27 PM 1/3/2016 4:08:35 PM 0:00:08 B
1/3/2016 4:08:35 PM 1/3/2016 4:08:46 PM 0:00:11 A``
For any given time, there is a unique task: there is no overlap. Given this, I want to create a "bar chart" that shows the tasks being performed using colors, something like the image below. I want the length of the bars to reflect the duration of the task. I want a bar for each day (or week). How can I do this in Python?
EDIT:
As per Evert's suggestion, I ended up doing this:
import pandas as pd
from datetime import datetime
# Read the data in (Time_Sample.txt contains the data I have posted above):
df=pd.read_csv('Time_Sample.txt',sep='\t')
df['Day']=df['Process Start'].str[0:9].str.strip()
df['Week_Day']=df['Day'].apply(lambda x: datetime.strptime(x,"%m/%d/%Y").weekday())
df['Duration_Seconds']=((df['Duration'].str[-5:].str[0:2]).map(float)*60 + \
(df['Duration'].str[-2:]).map(float))
df['Seconds_Since_Midnight'] = df['Process Start'].apply(lambda x:( datetime.strptime(x,"%m/%d/%Y %I:%M:%S %p") - datetime.strptime(x,"%m/%d/%Y %I:%M:%S %p").replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds())
df['Color']=df['Task'].map({'A':'yellow','B':'green','C':'blue'})
plt.figure()
plt.barh(bottom=df['Week_Day']+0.1, width=df['Duration_Seconds'], height=0.8,left=df['Seconds_Since_Midnight'], color=df['Color'], edgecolor = "none")
This gave me:
Now I know enough to get started, and I can customize further. Thank you:)