我正在尋找一個python替代連接。python合併基於鍵的字典列表
我想獲得一天的每一秒的列表,並根據時間戳將數據加入到該列表中。我有這麼遠,是這樣的:
keys=('DRIP_ID','DESCR','OBJECT','TIMESTAMP','DRIP_R1','DRIP_R2','RT_DISP1','RT_DISP2','DAY','TIME')
的鍵是列名
rawdata=[['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701063825','N242','N508','10','14','20150701','063825'],
['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701064327','N242','N508','10','14','20150701','064327'],
['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701085717','N242','N508','10','14','20150701','085717'],
['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701100116','N242','N508','10','14','20150701','100116'],
['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701191611','N242','N508','10','14','20150701','191611'],
['242418',"242418 Rechts.BD242418: tot Oudkarspel - - ${pijlop} N242 10 min - N508 14 min${pijlr}",'BD242418','20150701213616','N242','N508','10','14','20150701','213616']]
的RAWDATA是什麼出來的軟件
sec = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59']
mm = sec
hh = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23']
timestamp=()
time = []
dictData = []
# Dictionary with all seconds (HHMMSS) in 1 day
for ih, uur in enumerate(hh):
if ih < 24:
for im, minutes in enumerate(mm):
if im < 60:
for isec, secs in enumerate(sec):
if isec < 60:
timestamp = str(uur)+str(minutes)+str(secs)
timeDict = dict()
timeDict['DRIP_ID']=""
timeDict['DESCR']=""
timeDict['OBJECT']=""
timeDict['TIMESTAMP']=""
timeDict['DRIP_R1']=""
timeDict['DRIP_R2']=""
timeDict['RT_DISP1']=""
timeDict['RT_DISP2']=""
timeDict['DAY']=""
timeDict['TIME']=timestamp
time.append(timeDict)
在這裏,我提出的所有的秒,並給他們相同的密鑰,以便於匹配
# Turn raw data into dictionary
for row in rawdata:
dictionary = dict(zip(keys, row))
dictData.append(dictionary)
然後我拿RAWDATA並把它轉換成一個字典,以及
#Join, sort off
compleet=()
for t in time:
t.update(dictData)
compleet.append(t)
print len(compleet)
print compleet[1]
然而,當我運行它,我得到的錯誤:
ValueError: dictionary update sequence element #0 has length 10; 2 is required
這使我相信,我只能更新鍵:值對,但我不確定這是否正確。
此外:它是1:1連接。 1個時間戳只能有1個測量。 不是每一秒都有一個測量。 「加入對」將是對「TIME」
我理解輸入,但不理解預期輸出。你從輸入的例子中得到了什麼輸出? –
@TreyHunner我需要一張桌子,一天中的所有時間,以及他們所應用的測量。在後面的過程中,我需要填補那裏的空白。 – userBZ
這聽起來像你可能需要一個字典與每個鍵的值列表:http://stackoverflow.com/a/7919673/98187 –