【对比Python】日志处理1

任务:每三行记录一条日志,把日志整理成结构化文件

Python

1 import pandas as pd
2 import numpy as np
3 log_file = 'E://txt//access_log.txt'
4 log_info = pd.read_csv(log_file,header=None)
5 log_g=log_info.groupby(log_info.index//3)
6 rec_list = []
7 for i,g in log_g:
8 ??? rec = g.values.reshape(1*3)
9 ??? rec[1] = rec[1].split(":")[-1].replace("#","")
10 ??? rec="\t".join(rec)
11 ??? rec = np.array(rec.split("\t"))
12 ??? rec = rec[[6,7,0,1,3,4,8,5]]
13 ??? rec_list.append(rec)
14 rec_df = pd.DataFrame(rec_list,columns=["USERID","UNAME","IP","TIME","URL","BROWER","LOCATION","module"])
15 print(rec_df)

集算器

  A  
1 E://txt//access_log.txt  
2 =file(A1).import@s()  
3 =A2.group((#-1)\3)  
4 =A3.(~.(_1).concat("\t").array("\t"))  
5 =A4.new(~(7):USERID,~(8):UNAME,~(1):IP,~(2):TIME,~(4):URL,~(5):BROWER,~(9):LOCATION,left(~(6).array("\:")(2),-1):module)  

有了按行号分组的机制,就可以用循环每次处理一组数据,简化难度。

现金官网游戏下载