0
也許它只是在一天晚了,我有一個大腦放屁,但是......友情似乎打破...... 1/Y = = Y(但y被明確定義,而不是1)
- 如果y> 0和y 1 <
- y被明確定義的(未NAN或未定義)
然後不應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
...所以熊貓'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
這裏給full code as a jupyter notebook的鏈接。
更新:更多logs and code in this folder。
您使用的是什麼版本的熊貓(和Python)?我做了'rr = pd.read_csv(「https://www.dropbox.com/s/2t03ia7vp1vfx0z/rr.csv?dl=1#」,names = ['index','rr']).rr'和從'替換'行向前運行一切,並且它工作正常。 –
你確定你沒有打印'1./y.tail()'而不是'(1./y).tail()'嗎? – Kartik
@Kartik這並不重要,因爲'y'只包含(0,1)中的值,所以'1/y'的所有條目都大於1. –