0

I want to concat all the values in the rows from all columns. See below examples for more details.

Input --->

col_1 col_2   
1      a  
2      b  
3      c  
4      d  

Output----->

col_1     col_2  
1_2_3_4   a_b_c_d  

Is it possible to perform such operation using pandas in python?

1 Answer 1

2

Using apply with join ,after convert all value to string type

s=df.astype(str).apply('_'.join).to_frame(0).T
s
Out[247]: 
     col_1    col_2
0  1_2_3_4  a_b_c_d
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.