Log processing 2

Task:Each piece of log has indefinite rows, and each row with the same mark indicates that it is a piece of record.

Python

1 import pandas as pd
2 log_file = 'E://txt//Indefinite _info.txt'
3 log_info = pd.read_csv(log_file,header=None)
4 log_g = log_info.groupby(log_info[0].apply(lambda x:x.split("\t")[0]),sort=False)
5 columns = ["userid","gender","age","salary","province","musicid","watch_time","time"]
6 df_dic = {}
7 for c in columns:
8     df_dic[c]=[]
9 for index,group in log_g:
10     rec_dic = {}
11     rec = group.values.flatten()
12     rec = '\t'.join(rec).split("\t")
13     for r in rec:
14         v = r.split(":")
15         rec_dic[v[0]]=v[1]
16     for col in columns:
17         if col not in rec_dic.keys():
18             df_dic[col].append(None)
19         else:
20             df_dic[col].append(rec_dic[col])
21 df = pd.DataFrame(df_dic)
22 print(df)

esProc

  A  
1 E://txt//Indefinite _info.txt  
2 =file(A1).import@s()  
3 [userid,gender,age,salary,province,musicid,watch_time,time]  
4 =A2.group@o(_1.array("\t")(1))  
5 =A4.(~.(_1.array("\t")).conj().id().align(A3,~.array("\:")(1)).(~.array("\:")(2))).conj()  
6 =create(${A3.concat@c()}).record(A5)  

The merge grouping of esProc and the special alignment operation make the log processing very easy.