将 log 日志保存为 .xlsx (excel) 文件
import pandas as pd
import re
from collections import defaultdict
# 读取日志文件
log_lines = []
with open('log.txt', 'r') as file:
log_lines = file.readlines()
# 解析数据
data = defaultdict(lambda: defaultdict(dict))
for line in log_lines:
match = re.search(r'Dataset: (\w+), influence_p: ([\d.]+), Algorithm: (\w+), Influence: ([\d.]+)\.', line)
if match:
dataset, influence_p, algorithm, influence = match.groups()
data[dataset][float(influence_p)][algorithm] = float(influence)
# 创建 DataFrame 并保存到 Excel
writer = pd.ExcelWriter('output.xlsx', engine='openpyxl')
for dataset, dataset_data in data.items():
df = pd.DataFrame(dataset_data).T # 转置以得到所需的格式
df.index.name = 'influence_p'
df.to_excel(writer, sheet_name=dataset)
writer.save()
log.txt 文件内容如下:
[2023-12-12 23:08:26] exp3_p.py(26) : Start
[2023-12-12 23:08:26] exp3_p.py(42) : Dataset: cora, influence_p: 0.1, Algorithm: degree, Influence: 209.5.
[2023-12-12 23:08:27] exp3_p.py(42) : Dataset: cora, influence_p: 0.15, Algorithm: degree, Influence: 353.22.
[2023-12-12 23:08:27] exp3_p.py(42) : Dataset: cora, influence_p: 0.2, Algorithm: degree, Influence: 512.06.
[2023-12-12 23:08:28] exp3_p.py(42) : Dataset: cora, influence_p: 0.25, Algorithm: degree, Influence: 714.1.
[2023-12-12 23:08:29] exp3_p.py(42) : Dataset: cora, influence_p: 0.3, Algorithm: degree, Influence: 971.52.
[2023-12-12 23:08:30] exp3_p.py(42) : Dataset: cora, influence_p: 0.35, Algorithm: degree, Influence: 1122.76.
[2023-12-12 23:08:31] exp3_p.py(42) : Dataset: cora, influence_p: 0.4, Algorithm: degree, Influence: 1272.6.
[2023-12-12 23:08:32] exp3_p.py(42) : Dataset: cora, influence_p: 0.45, Algorithm: degree, Influence: 1440.48.
[2023-12-12 23:08:33] exp3_p.py(42) : Dataset: cora, influence_p: 0.5, Algorithm: degree, Influence: 1549.68.
[2023-12-12 23:15:29] exp3_p.py(42) : Dataset: cora, influence_p: 0.1, Algorithm: celf, Influence: 219.26.
[2023-12-12 23:30:16] exp3_p.py(42) : Dataset: cora, influence_p: 0.15, Algorithm: celf, Influence: 371.78.
[2023-12-12 23:54:09] exp3_p.py(42) : Dataset: cora, influence_p: 0.2, Algorithm: celf, Influence: 542.46.
[2023-12-13 00:31:52] exp3_p.py(42) : Dataset: cora, influence_p: 0.25, Algorithm: celf, Influence: 754.66.
[2023-12-13 01:26:47] exp3_p.py(42) : Dataset: cora, influence_p: 0.3, Algorithm: celf, Influence: 1023.0.
[2023-12-13 02:31:51] exp3_p.py(42) : Dataset: cora, influence_p: 0.35, Algorithm: celf, Influence: 1177.16.
[2023-12-13 03:46:16] exp3_p.py(42) : Dataset: cora, influence_p: 0.4, Algorithm: celf, Influence: 1339.88.
[2023-12-13 05:15:53] exp3_p.py(42) : Dataset: cora, influence_p: 0.45, Algorithm: celf, Influence: 1513.32.
[2023-12-13 06:52:13] exp3_p.py(42) : Dataset: cora, influence_p: 0.5, Algorithm: celf, Influence: 1623.44.
[2023-12-13 06:52:50] exp3_p.py(42) : Dataset: cora, influence_p: 0.1, Algorithm: imm, Influence: 211.42.
[2023-12-13 06:53:34] exp3_p.py(42) : Dataset: cora, influence_p: 0.15, Algorithm: imm, Influence: 362.02.
[2023-12-13 06:54:36] exp3_p.py(42) : Dataset: cora, influence_p: 0.2, Algorithm: imm, Influence: 527.92.
[2023-12-13 06:56:15] exp3_p.py(42) : Dataset: cora, influence_p: 0.25, Algorithm: imm, Influence: 710.12.
[2023-12-13 06:58:26] exp3_p.py(42) : Dataset: cora, influence_p: 0.3, Algorithm: imm, Influence: 978.46.
[2023-12-13 07:01:02] exp3_p.py(42) : Dataset: cora, influence_p: 0.35, Algorithm: imm, Influence: 1126.96.
[2023-12-13 07:04:10] exp3_p.py(42) : Dataset: cora, influence_p: 0.4, Algorithm: imm, Influence: 1296.26.
[2023-12-13 07:07:33] exp3_p.py(42) : Dataset: cora, influence_p: 0.45, Algorithm: imm, Influence: 1465.44.
[2023-12-13 07:11:09] exp3_p.py(42) : Dataset: cora, influence_p: 0.5, Algorithm: imm, Influence: 1580.3.
[2023-12-13 07:11:10] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.1, Algorithm: degree, Influence: 115.92.
[2023-12-13 07:11:10] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.15, Algorithm: degree, Influence: 185.58.
[2023-12-13 07:11:10] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.2, Algorithm: degree, Influence: 272.08.
[2023-12-13 07:11:10] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.25, Algorithm: degree, Influence: 380.64.
[2023-12-13 07:11:11] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.3, Algorithm: degree, Influence: 542.42.
[2023-12-13 07:11:11] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.35, Algorithm: degree, Influence: 631.5.
[2023-12-13 07:11:12] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.4, Algorithm: degree, Influence: 707.68.
[2023-12-13 07:11:13] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.45, Algorithm: degree, Influence: 853.38.
[2023-12-13 07:11:13] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.5, Algorithm: degree, Influence: 948.72.
[2023-12-13 07:13:51] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.1, Algorithm: celf, Influence: 144.0.
[2023-12-13 07:20:15] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.15, Algorithm: celf, Influence: 236.78.
[2023-12-13 07:31:12] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.2, Algorithm: celf, Influence: 340.84.
[2023-12-13 07:48:30] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.25, Algorithm: celf, Influence: 473.32.
[2023-12-13 08:15:04] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.3, Algorithm: celf, Influence: 643.0.
[2023-12-13 08:47:23] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.35, Algorithm: celf, Influence: 741.84.
[2023-12-13 09:24:30] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.4, Algorithm: celf, Influence: 832.86.
[2023-12-13 10:10:00] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.45, Algorithm: celf, Influence: 982.34.
[2023-12-13 10:59:22] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.5, Algorithm: celf, Influence: 1082.12.
[2023-12-13 11:00:02] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.1, Algorithm: imm, Influence: 135.34.
[2023-12-13 11:00:49] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.15, Algorithm: imm, Influence: 220.88.
[2023-12-13 11:01:42] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.2, Algorithm: imm, Influence: 326.18.
[2023-12-13 11:02:43] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.25, Algorithm: imm, Influence: 454.36.
[2023-12-13 11:03:55] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.3, Algorithm: imm, Influence: 631.32.
[2023-12-13 11:05:25] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.35, Algorithm: imm, Influence: 728.46.
[2023-12-13 11:07:17] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.4, Algorithm: imm, Influence: 821.66.
[2023-12-13 11:09:44] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.45, Algorithm: imm, Influence: 966.58.
[2023-12-13 11:12:34] exp3_p.py(42) : Dataset: citeseer, influence_p: 0.5, Algorithm: imm, Influence: 1046.44.

浙公网安备 33010602011771号