How to convert string timestamp values to datetime64 dtype
<p>The resulting DataFrame below lists the <strong>Timestamp</strong> values as the strings:</p>

<pre><code>import pandas as pd
df = pd.DataFrame({'Time':['00:00:00:19','02:11:00:07','02:00:40:23']})
</code></pre>

<p>What method to use to convert these string values to datetime64 so the sum() and mean() functions could be applied to the column?</p>

<p>Below is the screenshot of the DataFrame as it shown in Notebook:</p>

<p>It's probably not the best way, but it's functional:</p>

<pre><code>durations = (df.Time.str.split(':', expand=True).applymap(int) * [24*60*60, 60*60, 60, 1]).sum(axis=1).apply(pd.Timedelta, unit='s')
</code></pre>

<p>Gives you:</p>

<pre><code>0   0 days 00:00:19
1   3 days 08:00:07
2   2 days 00:40:23
dtype: timedelta64[ns]
</code></pre>

<p>And <code>durations.sum()</code> will give you <code>Timedelta('5 days 08:40:49')</code></p>

<p>Okay - slightly easier:</p>

<pre><code>df.Time.str.replace('(\d+):(.*)', r'\1 days \2').apply(pd.Timedelta)
</code></pre>

python dataframe