使用这样的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
如何绘制一种直方图,每分钟都能显示一些KO和OK?
答案 0 :(得分:3)
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
df1.plot.bar()
如果您想限制为'KO'
:
df1.KO.plot.bar()