How to convert tuple values to strings?

  • #1
53
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:

Answers and Replies

  • #2
12,664
6,533
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.
 
  • #3
wle
327
149
Python:
t = ('A', 'p', 'p', 'l', 'e')
''.join(t)   # returns 'Apple'
 
  • Like
Likes msn009 and jedishrfu
  • #4
53
6
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
 

Related Threads on How to convert tuple values to strings?

  • Last Post
Replies
2
Views
3K
Replies
3
Views
617
Replies
4
Views
1K
Replies
1
Views
11K
  • Last Post
Replies
5
Views
13K
Replies
1
Views
699
  • Last Post
Replies
15
Views
2K
Replies
9
Views
27K
  • Last Post
Replies
3
Views
244
Replies
6
Views
5K
Top