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

标签 python pandas 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 数量?

最佳答案

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

关于python - 从时间序列的数据帧中获取失败和成功的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38360546/

相关文章:

python - 执行此搜索算法的更有效方法?

python - 如何使用 float64 nan 选择行?

python - 使用 pandas 读取 csv 文件,其中列由不同数量的空格和逗号分隔

python - 将文本列拆分为 Pandas 数据框中的列表列,没有明确的拆分序列

r - 如何使用 R 按模式识别列并将其转换为日期时间?

python - 从 Pandas 数据帧创建边缘列表

python - 值更新的 Json 写入问题

Python 不会 eval() 代码

python - 如何验证一步是python中的原子操作还是现在

r - 将R中选定列中的所有NA替换为FALSE