0

I have a single pandas dataframe like this:

EMP ID
1111
2222
3333
4444

I want to concatenate the values into a single string and store it in a variable like this:

emp_ids = "1111,2222,3333,4444"

Is that possible? If yes, how?

1 Answer 1

3

use ','.join:

emp_ids = ','.join(df['EMP ID'])

If the original type is not string (e.g., int):

emp_ids = ','.join(df['EMP ID'].astype(str))
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.