模拟collections容器解析数据
作者:互联网
# -*- coding:utf-8 -*-
import re
import pandas as pd
import numpy as np
package_dict = {
"com.tencent.mobileqq":"QQ",
"com.ss.android.ugc.aweme":"抖音",
"com.qiyi.video":"爱奇艺",
"com.smile.gifmaker":"快手",
"tv.danmaku.bili":"哔哩哔哩",
"com.UCMobile":"UC浏览器",
"com.autonavi.minimap":"高德地图",
"com.tencent.mtt":"QQ浏览器",
"com.tencent.karaoke":"全民k歌",
"com.ss.android.article.video":"西瓜视频",
"com.ss.android.article.news":"今日头条",
"com.sina.weibo":"微博",
"com.jingdong.app.mall":"京东",
"com.youku.phone":"优酷",
"com.suning.mobile.ebuy":"苏宁易购",
"com.ximalaya.ting.android":"喜马拉雅",
"com.dianping.v1":"大众点评",
"com.tencent.qqmusic":"QQ音乐"
}
list_aveTime = []
package_count = dict()
with open("./appStartTimeAm.csv","r") as f:
for lines in f.readlines():
line = lines.strip()
# print(line)
app_list = line.split(',',6)
# print(app_list[6])
app_name = app_list[0].split('/',1)[0]
waitTime = app_list[4]
if app_list[6] != "TRUE":
continue
app_waitTime = (app_name + ':'+ waitTime).split(':')
# print(app_waitTime)
name = app_waitTime[0]
time = app_waitTime[1]
if name not in package_count:
package_count[name] = list()
package_count[name].append(int(time))
for key, val in package_count.items():
name = package_dict[key]
ave_time =np.mean(val)
print(name,ave_time)
list_aveTime.append([name,ave_time]+val)
# ,columns=['name','ave_time','第1次','第2次','第3次','第4次','第5次','第6次',
# '第7次','第8次','第9次','第10次']
df = pd.DataFrame(list_aveTime)
df.to_excel('waitTime解析结果.xlsx',index=False)
from collections import defaultdict
import pandas as pd
all_data = defaultdict(list)
data = pd.read_csv(r'./appStartTimeAm.csv')
app_name = data['appName']
waitTime = data['waitTime']
ColdStart = data['isNewColdStart']
for Name, wait,cold_start in zip(app_name,waitTime,ColdStart):
print(Name,wait,type(cold_start))
for i in data['appName'].unique():
if Name == i and cold_start:
all_data[Name].append(wait)
else:
if isinstance(type(cold_start),float):
continue
df = pd.DataFrame.from_dict(all_data, orient='index')
df.to_excel("waitTime解析表.xlsx")
标签:容器,name,data,app,list,waitTime,collections,解析,com 来源: https://blog.csdn.net/weixin_38185649/article/details/112843220