0

How can I concatenate columns and rows like this?

In:
  a  |  b  |  c  |  e
-----------------------
 mm    af    bn    nn
 pp    af    bn    yy

Out:

  b  |  c  |  final
------------------
af      bn    mm:nn&pp:yy

1 Answer 1

2

We can do column modify before groupby with agg

out = df.assign(final=df.a+':'+df.e).groupby(['b','c'],as_index=False).agg({'final':'&'.join})
out
Out[198]: 
    b   c        final
0  af  bn  mm:nn&pp:yy
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Beny. it's a correct answer. but I edit out. I want separate column by ":" char.

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.