Booom...........

LabNotes and Random Thoughts...............
Showing posts with label pandas. Show all posts
Showing posts with label pandas. Show all posts

Monday, May 16, 2016

summ up the time

parse time

This scirpt is on how to sum up the time series.

I am watching a series of videos on machine learning. What I want is to find out the toltal time I have to spend on all the lectures.

So I decided to script it up. I just copy pasted the series name and timings into a text bcoz i'm lazy to code it up using request :)

Rest of the coding is in python pandas . Its very simple

In [1]:
import pandas as pd
In [2]:
with open( "ts.txt", 'r' ) as fh:
    data = fh.readlines()
In [3]:
data[0:10]
Out[3]:
['Chapter 1: Introduction (slides, playlist)\n',
 '\n',
 '    Opening Remarks and Examples (18:18)\n',
 '    Supervised and Unsupervised Learning (12:12)\n',
 '\n',
 'Chapter 2: Statistical Learning (slides, playlist)\n',
 '\n',
 '    Statistical Learning and Regression (11:41)\n',
 '    Curse of Dimensionality and Parametric Models (11:40)\n',
 '    Assessing Model Accuracy and Bias-Variance Trade-off (10:04)\n']
In [4]:
# capture all the time slot of each video into a list

ts = list()

for e,i in enumerate(data[0:]):
    if i.startswith("Chapter"):
        pass
    if i.startswith(" "):
        ts.append( "0:" + i.split(" ")[-1].replace("(",'').replace(")","").replace('\n','') )

print ts
['0:18:18', '0:12:12', '0:11:41', '0:11:40', '0:10:04', '0:15:37', '0:14:12', '0:13:01', '0:8:24', '0:15:38', '0:14:51', '0:14:16', '0:22:10', '0:10:25', '0:9:07', '0:9:53', '0:7:28', '0:7:12', '0:7:37', '0:17:42', '0:10:07', '0:10:14', '0:8:22', '0:5:01', '0:14:01', '0:13:33', '0:10:07', '0:11:29', '0:14:35', '0:11:21', '0:7:40', '0:13:44', '0:12:26', '0:5:26', '0:14:06', '0:8:43', '0:12:37', '0:15:21', '0:5:27', '0:4:45', '0:15:48', '0:10:36', '0:10:32', '0:5:32', '0:16:34', '0:14:59', '0:13:13', '0:10:10', '0:10:45', '0:21:11', '0:12:15', '0:14:37', '0:11:45', '0:11:00', '0:13:45', '0:12:03', '0:10:13', '0:15:35', '0:11:35', '0:8:04', '0:15:04', '0:14:47', '0:10:13', '0:7:54', '0:12:37', '0:17:39', '0:17:17', '0:14:45', '0:9:24', '0:6:28', '0:6:31', '0:6:33']

Now to sum it up using pure python is time consuming. So I used pandas timedelta to convert it to a time series

In [5]:
tsSer = pd.Series(ts)

tsTd = pd.to_timedelta(tsSer)

print "Total Time taken for the entire Series to watch : ", tsTd.sum()
Total Time taken for the entire Series to Watch :  0 days 14:09:57