Regaring to this question/answer, is there a way to accomplish the same function for a pandas dataframe structure without casting it as a numpy array?
s[s.diff() != 0].index.tolist()
Output:
[0, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16]
s = pd.Series([1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 5, 5, 5])
print(s.diff()[s.diff() != 0].index.values)
OR:
df = pd.DataFrame([1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 5, 5, 5])
print(df[0].diff()[df[0].diff() != 0].index.values)
Output:
[ 0 5 8 9 10 11 12 13 14 15 16]
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