I have a dataframe with two columns. The columns is Word and Tag. The df looks as follows:
Word Tag
0 DNA O
1 , O
2 adalah O
3 ) X
4 , Y
5 ikatan P
6 10 O
7 , O
8 4 Q
9 pasangan Q
10 abad A
11 20 B
12 , C
13 bersamaan D
and I'd like to merge some row contains numbers with commas , number+,+number to one row. so the output should be the following:
Word Tag
0 DNA O
1 , O
2 adalah O
3 ) X
4 , Y
5 ikatan P
6 10,4 O
7 pasangan Q
8 abad A
9 20 B
10 , C
11 bersamaan D
Any ideas? Thanks in advance.
I have tried:
coma = df['Word'].shift().ne(',').mul(df['Word'].ne(',')).cumsum()
new_df = df.groupby(coma, as_index=False).agg({'Word' : ''.join, 'Tag' : 'first'})
print(new_df)
but it also combines words and commas, meanwhile I just want to combine numbers and commas