[英]Seaborn lineplot high cpu; very slow compared to matplotlib
我有以下数据帧。
In [12]: dfFinal
Out[12]:
module vectime vecvalue
1906 client1.tcp [1.1007512, 1.1015024, 1.1022536, 1.1030048, 1... [0.0007512, 0.0007512, 0.0007512, 0.0007512, 0...
1912 client2.tcp [1.10079784, 1.10159568, 1.10239352, 1.1031913... [0.00079784, 0.00079784, 0.00079784, 0.0007978...
1918 client3.tcp [1.10084448, 1.10168896, 1.10258008, 1.1036111... [0.00084448, 0.00084448, 0.00089112, 0.0010310...
我想为每个模块绘制timeSeries vecvalue
vs vectime
。
为此,我可以这样做:
1)Matplotlib
start = datetime.datetime.now()
for row in dfFinal.itertuples():
t = row.vectime
x = row.vecvalue
x = runningAvg(x)
plot(t,x)
total = (datetime.datetime.now() - start).total_seconds()
print("Total time: ",total)
这样做需要0.07005
秒才能完成。
2)Seaborn
start = datetime.datetime.now()
for row in dfFinal.itertuples():
t = row.vectime
x = row.vecvalue
x = runningAvg(x)
DF = pd.DataFrame({'x':x, 't':t})
sns.lineplot(x='t', y='x', data=DF)
total = (datetime.datetime.now() - start).total_seconds()
print("Total time: ",total)
这样做需要19.157463
秒才能完成。
为什么会有这么大的差异? 我做错了什么,处理一个相当小的DF需要很长时间?
在对lineplot
的调用中设置ci=None
; 否则,将计算置信区间,从而导致一些昂贵的(和不必要的) df.groupby
调用。
旁白: snakeviz
模块是快速查找计算瓶颈的绝佳工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.