python 3.x - How pandas diff handles bool values? -


here result of explicit subtract

>> true - false 1 >> false - true -1 

and here result of pandas.series.diff

>> x = pd.series([true,false,true]) >> x.diff()  0     nan 1    true 2    true dtype: object 

however, expected get

0     nan 1      -1 2       1 dtype: object 

why results differ , how pandas treats bool in case?

from series.py

result = algorithms.diff(_values_from_object(self), periods) 

from algorithms.py

out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] 

thus, results in subtraction of 2 numpy boolean arrays.

and pointed in comments, numpy subtracts boolean values in own way different native python subtraction

>> np.array([true, false]) - np.array([false, true]) array([ true,  true], dtype=bool) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -