繁体   English   中英

大熊猫单元格中的Omnet ++ /数据(列表)与pandas系列(列)

[英]Omnet++ / Data in a pandas cell(list) vs pandas series(column)

所以我使用Omnet ++,一个离散时间网络模拟器,来模拟不同的网络场景。 在某些时候,可以进一步处理Omnet ++输出统计信息并将它们存储在.csv文件中。

有趣的是,每次( vectime )都有一个值( vecvalue )。 那些vectime / vecvalues存储在这样的.csv文件的单个单元格中。 当导入到Pandas Dataframe中时,我会得到类似的东西。

In [45]: df1[['module','vectime','vecvalue']]
Out[45]: 
              module                                            vectime                                           vecvalue
237  Tictoc13.tic[1]  [2.542245319062, 3.066965320033, 4.78723506093...  [0.334535581612, 0.390459633837, 0.50391696492...
249  Tictoc13.tic[4]  [2.649303071938, 6.02527384362, 21.42434044990...  [2.649303071938, 1.654927100273, 3.11051622577...
261  Tictoc13.tic[3]  [4.28876656608, 16.104821448604, 19.5989313700...  [2.245250432259, 3.201153958979, 2.39023520069...
277  Tictoc13.tic[2]  [13.884917126016, 21.467263378748, 29.59962616...  [0.411703261805, 0.764708518232, 0.83288346614...
289  Tictoc13.tic[5]  [14.146524815409, 14.349744576545, 24.95022463...  [1.732060647139, 8.66456377103, 2.275388282721...

例如,如果我需要为每个模块绘制每个vectime / vecvalue,今天我正在做以下事情......

%pylab

def runningAvg(x):
    sigma_x = np.cumsum(x)
    sigma_n = np.arange(1,x.size + 1)
    return  sigma_x / sigma_n

for row in df1.itertuples():
    t = row.vectime
    x = row.vecvalue
    x = runningAvg(x)
    plot(t,x)

......获得这个......

在此输入图像描述

我的问题是:在性能方面最好的是:

  • 按原样使用数据,意味着在每个单元格内使用这些数组,在DF上循环以绘制每个数组;
  • 将这些数组转换为pd.Series。 在这种情况下,还有什么比将模块作为索引更好?
  • 将这些数组导入pd.Series会让我受益匪浅吗?

谢谢!

好吧,我一直在想,似乎将Omnet数据转换为pd.Series可能没有我想象的那么高效。

这是我的两种方法:

1)按原样使用Omnet数据,在Pandas DF中列出。

figure(1)

start = datetime.datetime.now()

for row in df1.itertuples():
    t = row.vectime
    x = row.vecvalue
    x = runningAvg(x)
    plot(t,x)

total = (datetime.datetime.now() - start).total_seconds()
print(total)

运行上述操作时, total0.026571

2)将Omnet数据转换为pd.Series

为了获得相同的结果,我不得不多次移调该系列。

figure(2)

start = datetime.datetime.now()

t = df1.vectime
v = df1.vecvalue
t = t.apply(pd.Series) 
v = v.apply(pd.Series)
t = t.T
v = v.T

sigma_v = np.cumsum(v)
sigma_n = np.arange(1,v.shape[0]+1)
sigma   = sigma_v.T / sigma_n

plot(t,sigma.T)

total = (datetime.datetime.now() - start).total_seconds()
print(total)

对于后者, total0.57266

所以我似乎坚持使用方法1,循环遍历不同的行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM