我有一个DataFrame
似乎行为异常(?)的方式如下:
>>> a=z.to_dict(orient='records')
>>> b=z.to_dict(orient='records')
>>> a1=json.dumps(a)
>>> b1=json.dumps(b)
>>> a1 == b1
True
>>> a == b
False # <<<===== WHAT?!!!
>>> for i in xrange(z.shape[0]):
print i, a[i] == b[i]
0 True
...
9 True
10 True
11 True
12 False
13 True
14 True
...
20 True
21 False
22 True
...
29 False
30 True
...
40 True
41 True
42 False
43 True
44 True
...
50 False
51 True
52 False
...
这是什么意思?!
答案 0 :(得分:1)
@ juanpa.arrivlllaga钉了它。在浮动数据框中,当单元格为np.nan
np.nan == np.nan
时,评估为False
z = pd.DataFrame(np.random.randn(10, 10), columns=list('abcdefghij'))
z
a=z.to_dict(orient='records')
b=z.to_dict(orient='records')
a1=json.dumps(a)
b1=json.dumps(b)
a == b
True
a1 == b1
True
z.loc[5, 'd'] = np.nan
z
a=z.to_dict(orient='records')
b=z.to_dict(orient='records')
a1=json.dumps(a)
b1=json.dumps(b)
a == b
True
a1 == b1
False