I have a data frame. I want to detect the zero crossing a dataframe:
My code:
def zero_crossing(data):
    return np.where(np.diff(np.sign(np.array(data))))[0]
df1 = pd.DataFrame({'a':[1,2,-1,5,0,9,-6,7]},index=[100,101,102,103,104,105,106,107])
df1 = 
     a
100  1
101  2
102 -1
103  5
104  0
105  9
106 -6
107  7
print(zero_crossing(df1['a']))
Present output:
array([1, 2, 3, 4, 5, 6], dtype=int64)
Expected output:
[101,102,103,104,105,106]
                Use your result
df1.index[zero_crossing(df1['a'])]
Out[132]: Int64Index([101, 102, 103, 104, 105, 106], dtype='int64')
#df1.index[zero_crossing(df1['a'])].tolist()
#Out[133]: [101, 102, 103, 104, 105, 106]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With