I have two Pandas Series, I want to filter out data which has an index that is not followed by an index in the other Series. So when joining these Series, based on index, only every other datapoint should be from data1 and vice versa.
Code:
import pandas as pd
import matplotlib.pyplot as plt
data1={1:20, 3:30, 5:40, 6:50}
data2={2:10, 4:20, 7:30, 9:40}
data1=pd.Series(data1)
data2=pd.Series(data2)
print(data1)
print(data2)
ax=plt.subplot()
ax.plot(data1,marker='o')
ax.plot(data2,marker='o')
plt.show()
Output:
(Arrows show data points which I want filtered out)
1 20
3 30
5 40
6 50
dtype: int64
2 10
4 20
7 30
9 40
dtype: int64
Expected pandas function for solving my problem:
expectedData1=data1[data1.index.isNotFollowedBy(data2.index)]
expectedData2=data2[data2.index.isNotFollowedBy(data1.index)]
Expected output from that function:
1 20
3 30
6 50
dtype: int64
2 10
4 20
9 40
dtype: int64

