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
13,623
7,612
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
336
158
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?

Replies
4
Views
2K
  • Last Post
Replies
2
Views
3K
Replies
1
Views
12K
  • Last Post
Replies
15
Views
2K
Replies
1
Views
918
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
496
  • Last Post
Replies
1
Views
2K
Replies
21
Views
2K
Replies
5
Views
2K
Top