vissim学生版结果数据快速整理

由于本蓝没有正版vissim,只能用学生版来仿真,但是仿真次数多了,一次次的复制粘贴,一次次矩阵转置让在下苦不堪言。因此,我写了一个程序,只需要将所有仿真做完后,把结果复制到excel中,然后代码自动整理数据。代码如下:

import numpy as np
import pandas as pd
import random
import xlrd
from pandas import DataFrame

class result(object):
    def __init__(self,name,path,shape):
        self.name = name
        self.path = path
        self.shape = shape - 1
        
    def read(self,path,name,shape):
        ratings = pd.read_csv(self.path)
        times = ratings['times']       #read simulation times
        cal = ratings[name]            #read the column we want to arrange 
        times = np.array(times)        #change str to array
        
        R = np.zeros([max(times),self.shape + 1]) #constructs a matrix
        
        j = 0
        
        for i in range(len(times)):
            
          
            
            if j < self.shape: #if j < the number of columns
                R[times[i] - 1,j] = cal[i]
                j = j + 1

            else:
                
                R[times[i] - 1,j] = cal[i]
                j = 0
        print(R)
        return R
   
if __name__ == 'main':
fpath = "C:/Users/*****/Desktop/original.csv"
q = result('maxqueue',fpath,3)
q.read(fpath,'maxqueue',3)

不过总感觉这个代码写得有点冗余,希望大神们可以多多批评指正,小蓝一定虚心求教。

你可能感兴趣的:(vissim学生版结果数据快速整理)