也许是在当天晚些时候,我有一个大脑放屁,但是......
那么1 / y不应该是> 1?
我看到1 / y == y。 (取倒数是无操作的)。
# rr is a Series of dtype=float64
rr = rr.replace(np.inf, np.nan)
rr = rr.replace(-np.inf, np.nan)
rr = rr.replace(0, 999.9)
print rr.sum()
y = rr[(rr>0) & (rr<1)].copy() # include only those values >0, <1
print "A"
print y.tail()
print "B"
print (1./y).tail()
for i in y:
assert i>=0 and i<=1
for i in y:
i = 1/i
assert i>=1
for i in (1./y): # Seems like this look should be the same as the former.
print i, "GONNA FAIL"
assert i>=1
2125514.43816 # rr.sum() is well defined
A # y.tail()
0
229994 0.893194
229996 0.997238
229999 0.725193
230000 0.980193
230002 0.819778
Name: rr, dtype: float64
B # 1/y.tail() ALL THE SAME??!
0
229994 0.893194
229996 0.997238
229999 0.725193
230000 0.980193
230002 0.819778
Name: rr, dtype: float64
0.566025929312 GONNA FAIL
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
AssertionError
...关于熊猫的事情&#39; 1 /系列看起来有点时髦。
结果与y.rtruediv(1)
相同。
更新:链接到CSV文件:
import pandas as pd
import numpy as np
import io
import requests
url="https://www.dropbox.com/s/2t03ia7vp1vfx0z/rr.csv?dl=1#"
s=requests.get(url).content
rr=pd.read_csv(io.StringIO(s.decode('utf-8')))
rr = rr[rr.columns[-1]].rename('rr')
print pd.__version__ # 0.19.2
print np.__version__ # 1.13.0
答案 0 :(得分:0)
是熊猫的错误!
@RyanStout指出这是在pandas = 0.20.3,numpy = 1.12.1中修复的。升级库也为我修复了它。