从时间序列中的数据帧获取失败和成功的次数

2024-05-29 08:26:14 发布

您现在位置:Python中文网/ 问答频道 /正文

对于这样的数据帧:

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的数量


Tags: 数据数量timestatusok直方图pidko
1条回答
网友
1楼 · 发布于 2024-05-29 08:26:14
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

如果要限制为'KO'

df1.KO.plot.bar()

enter image description here

相关问题 更多 >

    热门问题