Current dataframe is as follows:
df = pd.read_csv('filename.csv', delimiter=',')
print(df)
idx uniqueID String
0 1 'hello'
1 1 'goodbye'
2 1 'goodbye'
3 1 'happy'
4 2 'hello'
5 2 'hello'
6 2 'goodbye'
7 3 'goodbye'
8 3 'hello'
9 3 'hello'
10 4 'hello'
11 5 'goodbye'
Expected Output:
idx uniqueID String
0 1 'hello'
1 1 'goodbye'
3 1 'happy'
4 2 'hello'
6 2 'goodbye'
7 3 'goodbye'
8 3 'hello'
10 4 'hello'
11 5 'goodbye'
Question: How do I remove the consecutive duplicates only of the same uniqueID?
What I've tried to do thus far:
df = df[(df['String '].shift() != df['String ']) | (df['uniqueID'] != df['uniqueID'])]
I'm not sure what case I need to include to ensure it looks specifically at the uniqueID. Any and all suggestions are appreciated. Thanks