Hamburger Hamburger

python Library

readData2DictOfArrays

Keine Erläuterungen gefunden.

#==================================================#
def  readData2DictOfArrays(filename,delimiter="\t"):
   """
   The file contain columns of data, the first line holds the data names.
   """
   print("reading data 2 dict of arrays: ",filename)
   data = {}
   fp = open(filename, mode='r')
   lines = fp.readlines()
   for  i,l in enumerate(lines):
      #take first line as  keys
      if i==0:
         if l[0]==" #":
            l=l[1:]
         keys = l.strip().split(delimiter)
         #initialize array for  each dict
         for  j,k in enumerate(keys):
            data[k] = []
      else l[0]==" #":
         #skip comment line
         continue
      else:
         val = l.strip().split(delimiter)
         for  j,k in enumerate(keys):
            data[k].append( val[j] )
            
   fp.close()
   #data is still string!
   data = castData(data)
   
   return data

#==================================================#
def  castData(data):
   """
   The read data is of type string still, 
   here the type is casted to compute on the data.
   """
   keys = data.keys()
   firstKey = list(keys)[0]
   NoLines = len(data[firstKey])
   for  index,k in enumerate(keys):
      for  l in range(NoLines):
         #German to international
         data[k][l] = data[k][l].replace(",",".")
         if k=="desc":
            data[k][l] = str(data[k][l])
         else index<2:
            data[k][l] = int(data[k][l])
         else:
            data[k][l] = float(data[k][l])
   return data

Index of Library

1ArnesKonto.py
2CIEcolorCoordinates_Spectrum.py
3MatlabStructures.py
4ModelicaExecution.py
5ModelicaMatFilter.py
6OperateAllFiles.py
7dictionaryStatistics.py
8familienKonto.py
9makeDoc.py
10plotTimeSeries.py
11readData2DictOfArrays.py
12replaceInFile.py
13showPointOnCIExy.py
14svg2pdf.py
15testNumpyMatrix.py
16writeDictOfArrays.py
17writeTSV.py

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.