Suppose I have timeseries data. How to filter data that only occurs in 1 days different?
Suppose the data is
date name
2015-04-03 A
2015-04-04 A
2015-04-05 A
2015-04-03 B
What I want to do is something like
df[df.shift(1).contains(df.name) or df.shift(-1).contains(df.name)]
that would give me
date name
2015-04-03 A
2015-04-04 A
2015-04-05 A
How to do this in pandas?
You want to wrap your conditions in parentheses and use the bitwise |
instead of or
:
In [83]:
df[(df['name'].shift(1) == df['name']) | (df['name'].shift(-1) == df['name']) ]
Out[83]:
date name
0 2015-04-03 A
1 2015-04-04 A
2 2015-04-05 A
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