0

I have a dataset of runners going through checkpoints it looks like this:

data = {'Runner': ['Tom', 'Joseph', 'Krish'], 
'Start': [30/04/2021 05:27:19, 30/04/2021 05:33:50, 30/04/2021 05:43:32],
'First Checkpoint': [30/04/2021 05:40:45, 30/04/2021 05:36:59, 30/04/2021 05:59:03],
'Second Checkpoint': [30/04/2021 05:42:50, 30/04/2021 05:42:31, 30/04/2021 06:01:19],
'Third Checkpoint': [30/04/2021 05:42:53, 30/04/2021 05:42:33, 30/04/2021 06:01:37]}  

df = pd.DataFrame(data)

I would like to visualize this data as a stacked barplot but using the Start column as the first ticker in the graph.

My problems are that datetime64[ns] is not supported by matplotlib and I can't find a workaround to even start plotting.

Any help on this?

Jack
  • 722
  • 3
  • 8
  • 24
  • How do you want to stack time-series data? What do you like on the x-axis and y-axis? – imdevskp May 07 '21 at 09:22
  • For visualization, each section needs to be converted into a numerical value, so I calculated how much time difference there is based on the start time by summing up the number of seconds, and visualized it as a numerical value. Does this match your intention? If it does, I will answer. – r-beginners May 07 '21 at 09:37
  • [Colab](https://colab.research.google.com/drive/1Q2o8PzyUTUOuWTInC3wrj33y8qrwzau1?usp=sharing) You can check it and delete it if you don't need it. – r-beginners May 07 '21 at 09:38

1 Answers1

0

You need to convert data to proper DateTime format using pd.to_datetime

data = {'Runner': ['Tom', 'Joseph', 'Krish'], 
        'Start': ['30/04/2021 05:27:19', '30/04/2021 05:33:50', '30/04/2021 05:43:32'],
        'First Checkpoint': ['30/04/2021 05:40:45', '30/04/2021 05:36:59', '30/04/2021 05:59:03'],
        'Second Checkpoint': ['30/04/2021 05:42:50', '30/04/2021 05:42:31', '30/04/2021 06:01:19'],
        'Third Checkpoint': ['30/04/2021 05:42:53', '30/04/2021 05:42:33', '30/04/2021 06:01:37']}  

df = pd.DataFrame(data)

for col in df.columns[1:]:
    df[col] = pd.to_datetime(df[col])
    
df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 5 columns):
 #   Column             Non-Null Count  Dtype         
---  ------             --------------  -----         
 0   Runner             3 non-null      object        
 1   Start              3 non-null      datetime64[ns]
 2   First Checkpoint   3 non-null      datetime64[ns]
 3   Second Checkpoint  3 non-null      datetime64[ns]
 4   Third Checkpoint   3 non-null      datetime64[ns]
dtypes: datetime64[ns](4), object(1)
memory usage: 248.0+ bytes
imdevskp
  • 2,103
  • 2
  • 9
  • 23