kulawyjoe kulawyjoe - 29 days ago 6
Python Question

get number of fails and success from dataframe in time series

I've given dataFrame:

Time Status ResponseTime PID
2016-07-13 17:33:49 OK 1623 42
2016-07-13 17:33:50 KO 1593 35
2016-07-13 17:33:50 OK 1604 19
2016-07-13 17:33:51 KO 1605 28
2016-07-13 17:33:51 OK 1617 42
2016-07-13 17:33:52 OK 1654 35
2016-07-13 17:33:52 OK 2044 19
2016-07-13 17:33:53 KO 1630 42


how using python Pands can I draw kind of a histogram which would present number of KOs and OKs for each minute?

Answer
text = """Time                    Status      ResponseTime     PID
2016-07-13 17:33:49     OK          1623             42
2016-07-13 17:33:50     KO          1593             35
2016-07-13 17:33:50     OK          1604             19
2016-07-13 17:33:51     KO          1605             28
2016-07-13 17:33:51     OK          1617             42
2016-07-13 17:33:52     OK          1654             35
2016-07-13 17:33:52     OK          2044             19
2016-07-13 17:33:53     KO          1630             42
2016-07-13 17:34:49     OK          1623             42
2016-07-13 17:34:50     KO          1593             35
2016-07-13 17:34:50     OK          1604             19
2016-07-13 17:34:51     KO          1605             28
2016-07-13 17:34:51     OK          1617             42
2016-07-13 17:34:52     OK          1654             35
2016-07-13 17:34:52     OK          2044             19
2016-07-13 17:34:53     KO          1630             42
"""

df = pd.read_csv(StringIO(text), sep='\s{2,}', engine='python', index_col=0, parse_dates=[0])

df1 = df.groupby(pd.TimeGrouper('Min')).Status.value_counts().unstack()
df1

enter image description here

df1.plot.bar()

enter image description here

If you want to limit to 'KO':

df1.KO.plot.bar()

enter image description here