0

How can i merge/join multiple text columns within a single pandas dataframe without concatenating the columns individually

e.g

d = pd.DataFrame({'A':['one','two','three'],'B':['London','New York','Tokyo'],'C':['UK','USA','Japan'],'D':['Hot','Hot','Cold']})

the output should be

0         one London UK Hot
1      two New York USA Hot
2    three Tokyo Japan Cold
Name: combined, dtype: object
1
  • The problem with using concat here is that i need to mention column names individually. Commented Jul 10, 2019 at 11:19

1 Answer 1

1

Use DataFrame.apply along axis=1 with join:

d.apply(' '.join, axis=1)

0         one London UK Hot
1      two New York USA Hot
2    three Tokyo Japan Cold
dtype: object
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what i was looking for. Thanks a lot :)

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.