From 2e6dee942f93a271cff3d69ba1ed60726cb8efcf Mon Sep 17 00:00:00 2001 From: p01254378 <1299268546@qq.com> Date: Wed, 23 Jun 2021 10:31:51 +0800 Subject: [PATCH] Get computer configuration info --- .../data_processing.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/backend/Computer_Configurations/data_processing.py diff --git a/src/backend/Computer_Configurations/data_processing.py b/src/backend/Computer_Configurations/data_processing.py new file mode 100644 index 0000000..b783690 --- /dev/null +++ b/src/backend/Computer_Configurations/data_processing.py @@ -0,0 +1,47 @@ +''' +Description: +Author: Fishermanykx +LastEditors: Fishermanykx +LastEditTime: 2021-06-23 10:31:07 +''' +import codecs +import pandas as pd + +with codecs.open('result.txt', 'r', 'utf-8') as f: + res = f.read() + res = eval(res) + print(len(res)) + +url_indexs = [1, 2, 21, 6, 5, 8, 3] +key_in_consideration = ['CPU', '主板', '内存', + '硬盘', '固态硬盘', '显卡', '机箱', '电源', '散热器'] +categories = [ + '经济实惠型', '家用学习型', '网吧游戏型', '商务办公型', '疯狂游戏型', '图形音像型', '豪华发烧型' +] +writer = pd.ExcelWriter('test.xlsx') + +for i in range(1, 8): + data = res[url_indexs[i-1]] + # 重新洗一遍数据 + new_dict = {} + + for item in data: + for key in item: + if key not in key_in_consideration: + continue + if key not in new_dict: + new_dict[key] = [item[key]['percentage']] + else: + new_dict[key].append(item[key]['percentage']) + if 'Info' not in new_dict: + new_dict['Info'] = [str(item)] + else: + new_dict['Info'].append(str(item)) + + new_list = [new_dict] + df = pd.DataFrame.from_dict(new_dict, orient='index').T + + # print(df) + + df.to_excel(writer, sheet_name=categories[i-1], index=False) +writer.save()