2

I got a problem when analyzing dataset about combining string together. The data frame looks like the one below:

IP      Event
01      check
01      redo
01      view
02      check
02      check
03      review
04      delete

As you can see, the IP contains duplicates. My question is, how can I get the results of combining the Event group by each IP in order.For example, the result I'm looking for is:

IP    result
01    check->redo->view
02    check->check
03    review
04    delete

2 Answers 2

3

try this:

In [27]: df.groupby('IP').agg('->'.join).reset_index()
Out[27]:
   IP              Event
0  01  check->redo->view
1  02       check->check
2  03             review
3  04             delete

or

In [26]: df.groupby('IP').agg('->'.join)
Out[26]:
                Event
IP
01  check->redo->view
02       check->check
03             review
04             delete
Sign up to request clarification or add additional context in comments.

Comments

1

Try this with lambda:

df.groupby("IP")['Event'].apply(lambda x: '->'.join(x)).reset_index()


  #  IP           Event
# 0   1  check->redo->view
# 1   2       check->check
# 2   3             review
# 3   4             delete

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.