How to convert tuple values to strings?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 2K views
msn009
Messages
53
Reaction score
6
i have a column in a dataframe that contains values in the form or tuples (example: ('A',) ) and I want to convert these values to string format so that ('A',) becomes 'A'
How do I do this in python for a dataframe? Thanks.
 
Last edited by a moderator:
Physics news on Phys.org
There's str function which will print any instance in textual form which is great for debug but it might not be what you want.

To get the best results, you would need to loop over your tuples, extract the data and print it.
 
Python:
t = ('A', 'p', 'p', 'l', 'e')
''.join(t)   # returns 'Apple'
 
  • Like
Likes   Reactions: msn009 and jedishrfu
thank you. in the end i decided to use a mapping method to convert the tuple values into a string format. it worked better for my situation