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

时间:2019-05-06 01:39:37

标签: python pandas performance omnet++

因此,我使用离散时间网络模拟器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)

...获得此...

enter image description here

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

  • 按原样使用数据,这意味着在每个单元格内使用这些数组,在DF上循环绘制每个数组;
  • 将这些数组转换为pd.Series。在这种情况下,最好还是将模块作为索引?
  • 将这些数组取消嵌套到pd.Series中会受益吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

好吧,我想知道了,看来将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,在不同的行上循环。