原始数据:
概况:
本文对服务器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_