streamlit+matplotlib分析log绘制报表、饼图、折线图

本文介绍如何利用Python的pandas处理服务器log,通过正则表达式提取错误时间,用matplotlib生成每小时错误次数的饼图和折线图,并在Streamlit应用中展示分析结果。
摘要由CSDN通过智能技术生成

原始数据:

 

概况:

本文对服务器log进行分析,pandas 提取错误日志,matplotlib图形化分析每小时出现错误的次数,最后通过streamlit展示在页面上

说明:

1、读取文件:打开本地log文件,逐行读取,如果符合过滤条件,放入pd里。 lst_log.append(line) df_etllog = pd.DataFrame({ 'message':lst_log})

2、数据解析:

正则提取到错误产生的时间df[‘new_col’] = df[‘selected_col’].str.extract(‘正则表达式’, expand = True)

对日期数据进行2次分段df_etllog1 = df_etllog.message.str.split( ':',expand = True)

df_etllog1.columns = ['datehour','minute','second'] 最终得到hour数据

对相同时间出现的次数进行计数 labelslist=list(df_etllog2['hour']) result = pd.value_

  • 0
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在 PyQt5 中绘制折线图(line chart),可以使用 Matplotlib 库。下面是一个简单的示例代码: ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QSizePolicy, QVBoxLayout, QWidget from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure class MainWindow(QMainWindow): def __init__(self): super().__init__() # 创建 Matplotlib 图形 self.figure = Figure(figsize=(5, 4), dpi=100) self.canvas = FigureCanvas(self.figure) self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # 创建一个垂直布局,并将 Matplotlib 图形添加到其中 layout = QVBoxLayout() layout.addWidget(self.canvas) # 创建一个 QWidget,用于放置布局 widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # 绘制折线图 self.plot() def plot(self): # 获取 Matplotlib 的 Axes 对象 ax = self.figure.add_subplot(111) # 准备数据 x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # 绘制折线图 ax.plot(x, y) # 添加标题和坐标轴标签 ax.set_title("Line Chart") ax.set_xlabel("X-axis") ax.set_ylabel("Y-axis") # 更新 Matplotlib 图形 self.canvas.draw() if __name__ == "__main__": app = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec_()) ``` 在这个示例中,我们首先创建了一个 Matplotlib 图形,并将其添加到一个垂直布局中。然后,我们定义了一个 `plot` 方法,用于绘制折线图。在 `plot` 方法中,我们获取了 Matplotlib 的 Axes 对象,并使用 `plot` 函数绘制折线图。最后,我们添加了标题和坐标轴标签,并更新了 Matplotlib 图形。 在 `__main__` 方法中,我们创建了一个 QApplication 对象,并将其传递给我们的 MainWindow 类。然后,我们显示了窗口并启动了应用程序的事件循环。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值