1

I have dataframe

 0     1     2
12     34   23
10     12    0

Desire output

upd_string
12, 34, 23
10, 12, 0

I try

df_upd = pd.DataFrame()
df_upd['upd_string'] = df[df.columns.values.tolist()].apply(str)

But it returns

ValueError: no results

1 Answer 1

4

First cast to strings if numeric and then apply join:

df.astype(str).apply(', '.join, axis=1)

for new DataFrame:

df_upd = pd.DataFrame({'upd_string': df.astype(str).apply(', '.join, axis=1)})
print (df_upd)
   upd_string
0  12, 34, 23
1   10, 12, 0
Sign up to request clarification or add additional context in comments.

6 Comments

it returns TypeError: data type not understood
It seems some data relative problem
Are data confidental?
I create data with df = pd.DataFrame(result_list) where result_list = [[12, 34, 23], [10, 12, 0]]
Problem has solved with restarting the kernel) Thank you!
|

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.