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
Post a Comment