【发布时间】:2019-10-03 20:54:04
【问题描述】:
我有以下数据框。
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) 海生
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 需要这么长时间?
【问题讨论】:
-
我遇到了同样的问题。我有 100 万个数据点,matplot lib 几乎可以立即绘制,而 seaborn 则需要永远。
标签: python pandas performance matplotlib seaborn