0

I have pandas DataFrame that has a number of columns (about 20) containing string objects. I'm looking for a simple method to add all of the columns together into one new column, but have so far been unsuccessful e.g.:

for i in df.columns:
    df[‘newcolumn’] = df[‘newcolumn’] + ‘/‘ + df.ix[:,i]

This results in an empty DataFrame column ‘newcolumn’ instead of the concatenated column.

I’m new to pandas, so any help would be much appreciated.

1
  • do you want the values of each column added together as well? Commented Jan 12, 2014 at 2:27

1 Answer 1

3
df['newcolumn'] = df.apply(''.join, axis=1)
Sign up to request clarification or add additional context in comments.

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.