2017-11-20 7 views
0

csvにカンマ区切り文字を追加できません。私はいくつかの提案を試みたが、何も動作していないようだ。具体的には、以下のリンク。 numpy savetxt is not adding comma delimiterNumpy savetxtデリミタがカンマを追加しない

コード:

def saveData(_stopEvent, _saveDataEvent, _mainQueue, _fileName): 
    while not _stopEvent.wait(0.1): 

     if not _saveDataEvent.set(): 

      while not _mainQueue.empty(): 

       toSort = _mainQueue.get() 

       f_handle = file(_fileName, 'a') 

       saveFormat = collections.OrderedDict() 
       saveFormat['type'] = ' ' 
       saveFormat['ID'] = ' ' 
       saveFormat['Date'] = ' ' 
       saveFormat['rtuTemperature'] = ' ' 
       saveFormat['rtuPressure'] = ' ' 
       saveFormat['uCTemperature'] = ' ' 
       saveFormat['uCVcc'] = ' ' 
       saveFormat['refPressure'] = ' ' 
       saveFormat['refAmbientTemperature'] = ' ' 

       saveFormatValues = None 

       #Ref data 
       if len(toSort) == 2: 
        timeStamp = str(datetime.datetime.utcnow().strftime('%m/%d/%Y %H:%m:%-S')) + '+1' 

        saveFormat['type'] = 'ref' 
        saveFormat['ID'] = 'SerialNumber' 
        saveFormat['Date'] = timeStamp 
        saveFormat['refPressure'] = toSort[0] 
        saveFormat['refAmbientTemperature'] = toSort[1] 

       #rtu data 
       if len(toSort) == 6: 
        saveFormat['type'] = 'rtu' 
        saveFormat['ID'] = toSort[0] 
        saveFormat['Date'] = toSort[1] 
        saveFormat['rtuTemperature'] = toSort[2] 
        saveFormat['rtuPressure'] = toSort[3] 
        saveFormat['uCTemperature'] = toSort[4] 
        saveFormat['uCVcc'] = toSort[5] 

       saveFormatValues = saveFormat.values() 
       print saveFormatValues, type(saveFormatValues), len(saveFormatValues) 

       np.savetxt(f_handle, [saveFormatValues], fmt='%s %s %s %s %s %s %s %s %s', delimiter=',') 

       f_handle.close() 

出力:

['ref', 'SerialNumber', '11/20/2017 14:11:22+1', ' ', ' ', ' ', ' ', '0.01', '64.2'] <type 'list'> 9 
['ref', 'SerialNumber', '11/20/2017 14:11:25+1', ' ', ' ', ' ', ' ', '0.01', '64.3'] <type 'list'> 9 
['rtu', '89011704252305474659', '11/20/2017 14:56:25+1', '2752', '320', '990', '2496', ' ', ' '] <type 'list'> 9 
['rtu', '89011704252305474683', '11/20/2017 14:56:25+1', '2752', '220', '1011', '2496', ' ', ' '] <type 'list'> 9 
['rtu', '89011704252305474519', '11/20/2017 14:56:26+1', '2727', '262', '858', '2496', ' ', ' '] <type 'list'> 9 
+0

十分に検索しませんでした。フォーマットを追加すると区切り文字は無視されます。 https://stackoverflow.com/questions/36202888/numpy-savetxt-does-not-export-delimiter-when-defining-fmt-for-each-column –

答えて

関連する問題