小编rak*_*kke的帖子

键入dict.keys(),但dict.get(key)返回None

我有一本字典词典,即dict[key1][key2]应该返回一个数字.如果我这样做key2 in dict[key1]返回True,但dict[key1].get(key2)返回None.

我想这里有一些非常基本的东西,但是我被卡住了.

由于key1是a string,而key2是a numpy.datetime64.

编辑:

key type: <type 'numpy.datetime64'>
key: 2014-08-11T02:00:00.000000+0200
Dict: {numpy.datetime64('2014-08-11T02:00:00.000000000+0200'): 1}
key in dict.keys() True
dict.items(): [(numpy.datetime64('2014-08-11T02:00:00.000000000+0200'), 1)]
dict.get(key): None
Run Code Online (Sandbox Code Playgroud)

编辑2:

由编辑3取代

编辑3(替换编辑2):

码:

vessel = df['Vessel'].iloc[0]
print "vessel:",vessel
ati = np.datetime64(df['ATI'].iloc[0])
print "ati type:",type(ati),"value:",ati
print "Self.sailing[vessel]:",self.sailing[vessel]
print "key in dict.keys():",ati in self.sailing[vessel].keys()
sailing = self.sailing[vessel].get(ati)
print "sailing:", sailing
print "dict[key]:",self.sailing[vessel][ati]
Run Code Online (Sandbox Code Playgroud)

输出:

vessel: VESSEL2
ati type: <type 'numpy.datetime64'> value: 2014-07-21T02:00:00.000000+0200
Self.sailing[vessel]: {numpy.datetime64('2014-07-21T02:00:00.000000000+0200'): …
Run Code Online (Sandbox Code Playgroud)

python dictionary numpy

1
推荐指数
1
解决办法
510
查看次数

标签 统计

dictionary ×1

numpy ×1

python ×1